问题
I want to know if there is way to not trigger CellValueChanged event in DataGridView when the value is changed programatically? I only want to process that event when the user changes the value manually, like by clicking or typing in one of the boxes. In my application I also set the value programatically and do not want to process that event.
Thanks, Ritesh
回答1:
Add a conditional to your handler that evaluates whether or not the handler should be used. Set the value to true when you are changing your CellValue programatically.
//set this to true when you want to skip handler
private bool _skipHandler = false;
void Handler(object sender, EventArgs e) {
if (skipHandler)
{
skipHandler = false;
return;
}
else
{
//handle accordingly
}
}
来源:https://stackoverflow.com/questions/32239592/do-not-trigger-cell-value-change-event-in-datagridview-when-the-value-is-changed