triggering events by code
-
i have a checkbox on my form and i have written a few lines of code on the checkbox.checkchanged event which fires everytime u check or uncheck the box. This works fine till u check it by clicking on it at runtime but the event doesnt fire when I type checkbox.checked = true. How cn i make the event fire through code..
-
i have a checkbox on my form and i have written a few lines of code on the checkbox.checkchanged event which fires everytime u check or uncheck the box. This works fine till u check it by clicking on it at runtime but the event doesnt fire when I type checkbox.checked = true. How cn i make the event fire through code..
If
checkbox.Checked
is already true, and you write thecheckbox.checked = true
, thencheckbox.checkchanged
will not fire, since thecheckState
is not being changed, Otherwise it will fire. Check using the statement likethis.checkbox.Checked = !this.checkbox.Checked;
BTW, If you want to call the eventHandler from any where else call like below
this.checkBox1_CheckedChanged(this, new System.EventArgs());
-
If
checkbox.Checked
is already true, and you write thecheckbox.checked = true
, thencheckbox.checkchanged
will not fire, since thecheckState
is not being changed, Otherwise it will fire. Check using the statement likethis.checkbox.Checked = !this.checkbox.Checked;
BTW, If you want to call the eventHandler from any where else call like below
this.checkBox1_CheckedChanged(this, new System.EventArgs());
hi jay, my code doesnt seem to fire when i type checkbox1.checked = true; even thouhg my checkbox state is false. please subscribe to this thread so i can reply
-
hi jay, my code doesnt seem to fire when i type checkbox1.checked = true; even thouhg my checkbox state is false. please subscribe to this thread so i can reply
Hi Mridang, First of all, please go through the msdn documents CheckBox.CheckedChanged[^] It should fire. There is no bug in the .net, concerning this. As I said in my previous post, check using again.
this.checkbox.Checked = !this.checkbox.Checked;
or
private void ChangeCheckBoxState(CheckBox cbx)
{
cbx.Checked = !cbx.Checked;System.Diagnostics.Debug.WriteLine("checked state transformed to " + this.checkBox1.Checked);
}
//
private void checkBox1_CheckedChanged(object sender, System.EventArgs e)
{
MessageBox.Show("Check Changed");}
You can explicitly also call the event handler, just to reconfirm as
this.checkBox1_CheckedChanged(this, new System.EventArgs());
I would also advice you to prepare a simple demo project to check the above phenomenon. Regards, Jay.