NewBie
NewBie

Reputation: 1844

Clear checked items from a listbox without firing itemcheck event

I got a checkedlist box in form2 (clbForm2) where i'm explicity mapping it to an item check event. Now i need to uncheck all the checked items of the control in Form1, from within form2. On unchecking the items, it'z firing the item check event. Is there any way to skip the event. I'd written code within that, which i dont want to run when called from form2. Please suggest a good way.

Upvotes: 2

Views: 1523

Answers (2)

musefan
musefan

Reputation: 48415

I would prefer to use a flag rather than to unbind/rebind...

Create a class level variable such as...

private bool processCheckChange = true;

Then in you event handler do...

OnCheckedChange()
{
   if(processCheckChange)
   {
      //Handle check change
   }
}

Then when you want to uncheck all items...

UncheckAllItems()
{
   processCheckChange = false;
   //Uncheck all items
   processCheckChange = true;
}

I think this should do the job

Upvotes: 2

CharithJ
CharithJ

Reputation: 47530

Unbind the event and rebind it.

_checkBox.CheckedChanged -= new System.EventHandler(yourEventHandler);
// Do Check as you want.
_checkBox.CheckedChanged += new System.EventHandler(yourEventHandler);

Upvotes: 6

Related Questions