suppressing a winform control's event handler

D

David C

This probably sounds like a newbie question, so please be gentle with
me.

Say you have a checkbox and have an event handler for the Checked
event.

I want that event handler to fire only in response to the human user
changing the checkbox, not when the value is set in code (such will be
a case when the checked property is set based on the value from the
database).

I have tried using a flag to suppress the event handler while checked
is set in code.

suppressCheckedHandler = true;
chkCompleted.Checked = valueFromDataBase;
suppressCheckedHandler = false;

private void chkCompleted_CheckedChanged(object sender,
System.EventArgs e)
{
if (suppressCheckedHandler)
return;
..........
}

Well, it sucks to have to have that that for every control, and for my
situation, I am getting caught up in the chicken or the egg quagmire.
This isn't an issue in ASP.NET and I don't remember this being the
case when I did VB 6.0 7 years ago.

So what programming model would you suggest besides having a flag to
maintain for each control?

Thanks in advance.
 

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