Do not trigger cell value change event in DataGridView when the value is changed programatically

醉酒当歌 提交于 2020-01-02 15:39:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!