Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent event firing after programmatically interacting with controls?

I have a CheckedBoxList. Also I have a ItemCheck event attached to it, so a fuction is executed after I checked an item. But the problem is, at one point in my program I need to programmatically check/uncheck items. And this action triggers the event function.

My guess is is also applies to other controls.

How can I prevent such behaviour? I need function to be run only when user interacts with it, not when I am doing something with control inside my app.

like image 642
serge1peshcoff Avatar asked Feb 07 '23 21:02

serge1peshcoff


1 Answers

You can wrap all your changes to CheckedBoxList in a function and use that function everytime. The code may look something like this:

private void UpdateCheckedListBox() // You would need to add your parameters
{
    checkedListBox1.ItemCheck -= checkedListBox1_ItemCheck;
    // your changes to checked list box goes here
    checkedListBox1.ItemCheck += checkedListBox1_ItemCheck;
}
like image 118
Bharat Gupta Avatar answered Feb 09 '23 12:02

Bharat Gupta