eastender
eastender

Reputation: 434

How do I find which rows have been updated in the underlying Datatable on updating the Datagridview?

This is what I am trying to achieve:

  1. DataTable populated using data from non database source
  2. This table is bound to a DataGridView using BindingSource
  3. The DataGridView is updated by the user, so that some cells now have new values.
  4. Because the table is bound to the datagridview its values are updated.

How do I get only the updated rows(the rows which have been edited) in the grid/datatable?

I have tried :

DataRow[] updatedRows = 
              _table.Select(null, null, DataViewRowState.ModifiedCurrent);

But this always returns 0 rows. Is there a way to get only the modified rows?

Worst case:

Thanks!

Upvotes: 3

Views: 6122

Answers (1)

DOK
DOK

Reputation: 32841

How about this:

DataTable changedRecordsTable = dataTable1.GetChanges();

You can find more details at How to: Retrieve Changed Rows

Upvotes: 2

Related Questions