以编程方式更改值时,请勿在DataGridView中触发单元格值更改事件 [英] Do not trigger cell value change event in DataGridView when the value is changed programatically
问题描述
我想知道是否有办法以编程方式更改值时不触发DataGridView中的CellValueChanged事件?
我只想在用户手动更改值时处理该事件,例如单击或键入其中一个框。在我的应用程序中,我还以编程方式设置了该值,并且不想处理该事件。
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.
感谢,
Ritesh
Thanks, Ritesh
推荐答案
向处理程序中添加一个条件,以评估是否应使用该处理程序。当您以编程方式更改CellValue时,将该值设置为true。
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
}
}
这篇关于以编程方式更改值时,请勿在DataGridView中触发单元格值更改事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!