Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Changes in datagridView are not immediately propagated to datatable
 

Changes in datagridView are not immediately propagated to datatable

Hi,

I have two datagrids bound to the same table. The table contains column "Visible". The first grid should display all the visible rows (that have value "True" in "Visible" column) and the second displays "Visible" column as check boxes so a user can select what rows should be visible.

The problem is the changes made to the first grid arepropagated to the secondonly whena second change is made: when Iclick on the check box nothing happens ti the first grid but when I click on another one the first change is propagated (not the second). Does anybody know is there any kind of buffering in DataGridView control and how can I force it to apply changes to the corresponding DataTable?

Thanks,

Dmitry

Dmitry Yakovlev  Thursday, November 20, 2008 11:44 AM

Try call the DataTable.AcceptChanges() method.

Myexp  Monday, November 24, 2008 7:27 AM

Ok, it seems the problem is the changes are applied only when the row containing the check box looses focus (e.g. if I uncheck it and click anywhere on the grid the changes appear in another grid.

So, now the question is there any way to force arow to loose the focux after afterthe check box has been clicked?

Dmitry

Dmitry Yakovlev  Thursday, November 20, 2008 12:15 PM

I fixed it in the following waybut it's really ridiculous.

private void displayDataGrid_CellContentClick(object sender, DataGridViewCellEventArgs e)

{

if (e.RowIndex >= 0 && e.ColumnIndex == 1)

{

var row = (DataRowView)this.displayDataGrid.Rows[e.RowIndex].DataBoundItem;

row.BeginEdit();

row["Visible"] = this.displayDataGrid[e.ColumnIndex, e.RowIndex].EditedFormattedValue;

row.EndEdit();

}

}

Any suggestions on what I do wrong are appreciated.

Dmitry

Dmitry Yakovlev  Thursday, November 20, 2008 1:27 PM

Try call the DataTable.AcceptChanges() method.

Myexp  Monday, November 24, 2008 7:27 AM

Unfortunately this doesn't work (I tried to replace row'sBeginEdit/EndEdit lines with just AcceptChanges).

It seems the row in data gridjust remains in edit mode after check box is clicked until another row is clicked. The interesting thing isthe changes are not applied evenwhen another control is clicked (outside datagrid). For me this looks like a bug in DataGridView implementation or at least very nasty feature (I don't know who would ever expect such behavior).

Thanks anyway for the try,

Dmitry

Dmitry Yakovlev  Tuesday, November 25, 2008 2:28 PM


1. BindingSource.EndEdit()Sends the changes to the DataTable (edits the row)
2. DataTable.AcceptChanges(); Ends the row edit

This process may happen automatically via other operations (eg. selecting other row in grid)

mick braz  Friday, September 18, 2009 1:56 AM

You can use google to search for other answers

Custom Search

More Threads

• UnhandledException?
• link on datagridview
• Refresh issues in custom painting DGV
• Best way to handle handle database schema change for generated dataset
• grid dispay
• Eject Cash Drawer
• Stupid db app problem
• DataTable internal index is corrupted: '5'. how to get ride of it ?
• windows application on a network
• Accessing a control in a datagrid