简体   繁体   English

在C#中选中复选框时防止listview的单击事件

[英]prevent click event of listview when check box is checked in c#

I have a list box with check box in it. 我有一个带有复选框的列表框。 but when i checked or unchecked the check box , list view click event is fired. 但是当我选中或取消选中复选框时,将触发列表视图单击事件。 I want to prevent click event when check box is checked or unchecked. 我想防止在选中或取消选中复选框时发生点击事件。

如果在复选框单击处理程序代码中将EventArgs对象Handled设置为true怎么办?

I think the only way to actually prevent the event from firing is to go into the generated code and comment out the line that wires up the event handler for check box control inside of the listview, like this: 我认为实际上防止事件触发的唯一方法是进入生成的代码,并注释掉连接事件处理程序以进行列表视图内部复选框控制的行,如下所示:

this.checkBox.Click += new System.EventHandler(this.checkBox_Click);

Either remove the above line(s) or comment them out. 删除上面的行或将其注释掉。

Beware, that this code will, potentially, be regenerated by the designer so you may have to routinely check that the code is not recreated for you. 注意,该代码可能会由设计人员重新生成,因此您可能必须定期检查是否未为您重新创建该代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM