Saving from a DataGridView

Posted Sat, Jul 22 2006 0:14 by bill
If you click on a button in a toolstrip, such as the save button on a BindingNavigator, the button never gets focus, so the DataGridView never looses focus, so the current changes are not persisted.
 
The first thing you need to do is call EndEdit on the DataGridView.  This will apply the cell's changes.  But if you are editing a data table, then you also need to call EndEdit on the BindingSource (or EndCurrentEdit on the currency manager if not using a BindingSource).  Calling EndEdit on the binding source will result in the row change being persisted and hence the dataset's diffgram will show that change.
 
So, your code should look something like:

Sub Save(…….)
   Me.CustomersDataGridView.EndEdit()
   Me.CustomersBindingSource.EndEdit()
   ' now save the dataset
   ……
End Sub
 
 
 
Filed under: ,