Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Checkbox value without raising event

Tags:

c#

I want to change Checkbox value without raising the onCheck event. I know there are work arounds like un registering ,changing the value then re- registering, Inside the event method based on flag either skip or evaluating the method statements or any other work arounds. I am looking for a cleaner ways for it.

like image 665
Ravisha Avatar asked Sep 16 '25 20:09

Ravisha


1 Answers

I know this is an old thread but the answer given is way too much trouble.
I almost never use the OnCheckedChanged event. I prefer to use OnMouseUp instead. That way you can set check boxes or radio buttons like you want them on startup without triggering the events.

In the OnMouseUp event check to see if the box is checked after the mouseUp happens like this..

private void chkBox1_MouseUp(object sender, MouseEventArgs e)
{
   if (chkBox1.Checked)
   {
      // do some stuff if the box is checked after a mouseup on it
   }   
}

I've been doing it this way for a long time. It use to be a big hassle to put flag variables in OnChanged Events to tell functions not to do anything while we are setting the box states. Using MouseUp is way easier. gc

like image 73
tralfaz Avatar answered Sep 19 '25 09:09

tralfaz