In my .NET/Forms app I have a DataGridView which is bound to a DataTable. The user selects a row of the DataGridView by double-clicking and does some interaction with the app. After that the content of the row is updated programmatically.

When the user selects a new row the changes on the previous one are automagically propagated to the DataTable by the framework. How can I trigger this update from my code so the user does not have to select a new row?


I guess it depends on what triggers the update to take place, if it is in a validation routine you could simply call that after the user clicks OK on editing the data. Your question is vague it would be easier to answer with more information. What is this interaction? Is it a dialog? What actually updates the data?


Here is the process to clarify this:

  1. user doubleclicks row
  2. app fetches data from db, processes fetched data and fills controls on the same form as the DataGridView
  3. user interacts with controls and finally presses apply button on the same form
  4. app processes state of controls, writes data to db and writes data to DataGridView

  5. IF user moves selection on DataGridView

  6. THEN changes are propagated to the bound DataTable

I would like to trigger 6 instantly after modifying the DataGridView from my code.

+2  A: 

I just had the same issue, and found the answer here:

When the user navigates away from the row, the control commits all row changes. The user can also press CTRL+ENTER to commit row changes without leaving the row. To commit row changes programmatically, call the form's Validate method. If your data source is a BindingSource, you can also call BindingSource.EndEdit.

Calling Validate() worked for me.

I used the form's Validate method for a DataGridView bound to a DataSet, thanks for the info, I was hunting all through the DataGridView methods and the DataSet for something.

Same here. Validate() works. Thank you!