DataGridView.IsCurrentRowDirty remains true after making changes to the database. I want to set it to false so that it does not start RowValidating when it has lost focus.
I have a DataGridView associated with a BindingList<T> . I handle the CellEndEdit event and save the changes to the database. After saving these changes, I would like DataGridView.IsCurrentRowDirty be set to true , since all cells in the row have been updated; however, it is set to false .
This causes problems for me, because when a row loses focus, it causes RowValidating , with which I process and check all three cells. Therefore, despite the fact that all the cells are valid and not one of them is contaminated, he still checks them all. This is waste.
Here is an example of what I have:
void dataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { // Ignore cell if it not dirty if (dataGridView.isCurrentCellDirty) return; // Validate current cell. } void dataGridView_RowValidating(object sender, DataGridViewCellCancelEventArgs e) { // Ignore Row if it not dirty if (!dataGridView.IsCurrentRowDirty) return; // Validate all cells in the current row. } void dataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e) { // Validate all cells in the current row and return if any are invalid. // If they are valid, save changes to the database // This is when I would expect dataGridView.IsCurrentRowDirty to be false. // When this row loses focus it will trigger RowValidating and validate all // cells in this row, which we already did above. }
I read the messages saying that I can call the Validate() method, but this will trigger RowValidating , which I am trying to avoid.
Any idea how I can set DataGridView.IsCurrentRowDirty to true ? Or maybe there is a way to prevent RowValidating from unnecessarily checking all cells?
Ecyrb source share