Reputation: 6451
In celledit ended I want to fire method only if the values changed
I have certain editable columns I want to fire the method only if the value already changed
the DataGridCellEditEndedEventArgs the property e.EditAction
always return comitted
Upvotes: 2
Views: 750
Reputation: 23198
You can listen to the DataGrid.PreparingCellForEdit event (or maybe DataGrid.BeginningEdit but I'm not 100% positive) and store the cell's value at that point.
Then instead of listening to DataGrid.CellEditEnded
, listen instead to DataGrid.CellEditEnding. This event is specifically designed to give you an option to cancel the editing so it's not treated as a commit. The DataGridCellEditEndingEventArgs for it provides a Cancel bool
property. Check if the new value is the same as the old value, and if it is, set the the Cancel
property to true
. Then when the CellEditEnded
event fires, its EditAction
will be Cancel
.
void MyGrid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs args)
{
//store current value
}
void MyGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs args)
{
//check if values are the same
if (valuesAreSame)
args.Cancel = true;
}
Upvotes: 2