如何禁用事件 [英] How to disable an event

查看:66
本文介绍了如何禁用事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果满足条件,我想禁用数据gridview的单元格双击事件。有可能吗?



我尝试过:



Ex。

如果(textboxusername.Text ==admin)

{

//禁用celldoubleclick

}

I want to disable cell double click event of data gridview if a condition is met. Is it possible?

What I have tried:

Ex.
If (textboxusername.Text =="admin")
{
//disable celldoubleclick
}

推荐答案

是:只需将其从事件处理程序中删除:

Yes: just remove it from the event handler:
myDataGridView.CellDoubleClick -= HandlerMethodName;

但更好的解决方案可能是在处理程序中进行检查并从那里返回。这样,如果文本框发生更改,则不必重新连接处理程序方法。

But a better solution might be to do your check in the handler and return from there. That way, if the text box changes, you don't have to reconnect the handler method.


这篇关于如何禁用事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆