DataGridView: Detect when a user has made changes to a row

  • Thread starter Thread starter davidbrit2
  • Start date Start date
D

davidbrit2

Guest
Im writing a small app (only 1 form) for internal use that presents a DataGridView bound to a DataTable from a DataSet. The goal is to allow end users to update data that our department has handled in the past, with a bit more usability features than simply editing the table in Enterprise Manager.

I need to be able to keep track of changes to the DataGridView, so that a typical "You have unsaved changes..." dialog can be displayed if the user tries to switch to a different category, which requires reloading the DataGridViews contents and throwing out the changes. This is no problem for adding and deleting rows - I can handle the UserAddedRow and UserDeletedRow events to make a note that the data is dirty.

Unfortunately, theres no UserEditedRow/UserEditedCell event that can be caught. I see CellValueChanged, but this fires even when cell values are changed programatically, and doesnt have any sort of flag in the event args denoting if it was a user-initiated change. Theres also the CellEndEdit event, but it doesnt tell you directly whether or not the value was actually changed.

Any ideas on how to tell if the user has just made changes to a row, without having to jump through too many hoops? The only time cells would be changed programatically is when loading the DataGridView, or during the DefaultValuesNeeded event (where I set the DataGridViewCell.Value property for certain columns).


Continue reading...
 
Back
Top