0

I need to know if an XtraGrid has been modified (value changed or rows added).

I can make a boolean var and change it on GridView_CellValueChanged:

void suppGridView_CellValueChanged(object sender, CellValueChangedEventArgs e) {
    isModified = true;
}

or
I can read all DataSource and check the DataRow.RowState property value (Modified or Added):

foreach (DataRow row in dataSource.Rows) {
    if (row.RowState == DataRowState.Modified || row.RowState == DataRowState.Added) 
        return true;
}

Do you know a simpler method?

DmitryG
  • 17,677
  • 1
  • 30
  • 53
Zyku
  • 1,429
  • 2
  • 23
  • 37

1 Answers1

4

You can know whether the data table changed in the following way:

DataTable changes = table.GetChanges(DataRowState.Added | DataRowState.Modified);
bool isModified = (changes != null);

here table is a DataTable.
From msdn:

DataTable.GetChanges Method:
Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges was called, filtered by DataRowState.

Remark: If no rows of the desired DataRowState are found, the method returns null.

DmitryG
  • 17,677
  • 1
  • 30
  • 53
Krishnakumar
  • 266
  • 2
  • 7