57838

Change Checkbox value without raising event

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.

Answer1:

You can derive from CheckBox class, override CheckBox.OnCheckedChanged Method and do not call the base class's OnCheckedChanged method and the event will not be fired. You can also have a property which indicates whether the event should be raised or not.

Answer2:

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

Answer3:

Remove and Reassign handler:

myCheckbox.Checked -= myCheckbox_Checked; myCheckbox.IsChecked = true; myCheckbox.Checked += myCheckbox_Checked;

Recommend

  • Handle ToggleButton in onResume()
  • In asp.net, page_load occuring before radio button OnCheckedChanged event
  • How to block incoming call when switch widget is on?
  • Glitches in adapter's getView method
  • Django all-auth Form errors not displaying
  • Why does Internet Explorer sometimes trigger a local storage event before the data's ready? [du
  • Insert null in a database
  • Trouble Attaching Call Back to Unobtrusive Validation Show Error
  • Extjs, handling success or failure when doing a standard submit in a form
  • How to replace TouchesBegan with UIGestureRecognizer
  • Fire callback when selection was made with select2 4.0, and retrieve the value of last selection
  • Cryptic error when trying to run POW
  • In matplotlib, how do you change the fontsize of a single figure?
  • Spring: No transaction manager has been configured
  • accepts_nested_attributes_for practical form use for in Rails 3
  • Object and struct member access and address offset calculation
  • Database structure design with variable amounts of fields
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • Recording logins for password protected directories
  • Update CALayer sublayers immediately
  • Splitting given String into two variables - php
  • JFileChooser in front of fullscreen Swing application
  • How do I fake an specific browser client when using Java's Net library?
  • How to get a value (ex: baseURL) in every Karate feature?
  • Check if a string to interpolate provides expected placeholders
  • Trying to switch camera back to front but getting exception
  • Cannot Parse HTML Data Using Android / JSOUP
  • Free memory of cv::Mat loaded using FileStorage API
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • unknown Exception android
  • Checking variable from a different class in C#
  • Programmatically clearing map cache
  • Busy indicator not showing up in wpf window [duplicate]
  • Observable and ngFor in Angular 2
  • failed to connect to specific WiFi in android programmatically
  • Unable to use reactive element in my shiny app
  • Why do underscore prefixed variables exist?