How to find which rows were updated in the underlying Datatable when updating a Datagridview?

This is what I am trying to achieve:

  • DataTable populated using data from source without database
  • This table is bound to a DataGridView using a BindingSource.
  • The DataGridView is updated by the user, so some cells now have new values.
  • Since the table is bound to a datagridview, its values ​​are updated.

How to get only updated rows (rows that were edited) in grid / datatable?

I tried:

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

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

Worst case:

  • Save a copy of the source table
  • Get a new table from datagridview data source
  • Compare all rows.

Thank!

+3
1

:

DataTable changedRecordsTable = dataTable1.GetChanges();

+2

Source: https://habr.com/ru/post/1756595/


All Articles