Bogus control property values

R

Ray Mitchell

Hello,

I have some existing perfectly-working code like the following to detect the
state of a CheckBox check change. I decided to rearrange a few things into
different files, and the existing code still works perfectly. However, if I
add any new CheckBoxes the events still occur but the Checked property of the
CheckBox always tests false on those new CheckBoxes. Only the GUI thread
itself is involved. I get no compiler warnings and nothing blows up during
running. I'm at a loss as to how I even begin to debug a problem like this.
Could it be some sort of timing issue? Suggestions are appreciated.

Thanks,
Ray

private void checkBox_CheckedChanged(object sender, EventArgs e)
{
if (checkBox.Checked == true)
{
statement1;
}
else
{
statement2;
}
}
 
F

Family Tree Mike

Ray Mitchell said:
Hello,

I have some existing perfectly-working code like the following to detect the
state of a CheckBox check change. I decided to rearrange a few things into
different files, and the existing code still works perfectly. However, if I
add any new CheckBoxes the events still occur but the Checked property of the
CheckBox always tests false on those new CheckBoxes. Only the GUI thread
itself is involved. I get no compiler warnings and nothing blows up during
running. I'm at a loss as to how I even begin to debug a problem like this.
Could it be some sort of timing issue? Suggestions are appreciated.

Thanks,
Ray

private void checkBox_CheckedChanged(object sender, EventArgs e)
{
if (checkBox.Checked == true)
{
statement1;
}
else
{
statement2;
}
}

If you have just this one handler routine for a set of CheckBoxes, then you
should not be using checkBox.Checked. checkBox is presumably a single
control in your UI. You should instead use something like the following:

if (((CheckBox) sender).Checked) statement1;
else statement2;

Mike
 
R

Ray Mitchell

Family Tree Mike said:
If you have just this one handler routine for a set of CheckBoxes, then you
should not be using checkBox.Checked. checkBox is presumably a single
control in your UI. You should instead use something like the following:

if (((CheckBox) sender).Checked) statement1;
else statement2;

Mike


Thanks Mike,

But I have a separate handler for every check box. Some recognize the
Checked property and some don't.

Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top