Detect when datagrid is modified

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi .NET gurus,

How can I detect when user has just edited any cell in my datagrid so that I can set a dirty flag in my application ?

Any help is very much appreciated.

Thanks.

Kinh Luan
 
One way is to create a derived DataGrid TextBox control.

Check this article out in the KnowlegeBase:

HOW TO: Extend the Windows Form DataGridTextBoxColumn Control to Custom-Format Data

Another way would be to use the CurrentCellChanged property of the DataGrid. The problem with that though is that only the current cell information is available. You can use this information and a couple of int variables to create a tracking mechanism.

If you need clarification let me know.
 
The method I use to flag a change in the form data is to declare a form-level
variable:

dim bState as boolean = false


then in each of the following DataGridView event, put in bState = True
CurrentCellDirtyStateChanged 'catches changes to the data
RowsRemoved 'catches rows deleted
UserAddedRow 'catches new rows
 
A side note on the earlier post - if you have your data adapter set to clear
before fill, the fill will trigger the RowsRemoved event, so be sure to set
your bState to False right after filling the adapter. Otherwise, your bState
will be set to True even if the user did not remove any rows.
 
Back
Top