Programatic or UI change in controls

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Let's say we have a check box and we have subscribed for the CheckedChanged
event. Now if the Checked property is changed, the event will fire. The
problem is that we dont know in the event handler how the event was fired
-from the code (ie programatically) or from UI (checking the box).
I get across this problem all the time and I cant think of any other
solution than setting a flag when changing some control's properties from my
code.

Thanks
 
Using a flag was the solution I used, too.

I've seen other people commenting here that they trap the MouseDown
event or the Click event or some such thing as a signal that the user
was interacting with the control, but that seemed unnecessarily complex
to me. A bool flag may be inelegant, but it's easy to understand and it
works.
 
Z said:
Let's say we have a check box and we have subscribed for the
CheckedChanged > event. Now if the Checked property is changed, the event
will fire. The
problem is that we dont know in the event handler how the event was fired
-from the code (ie programatically) or from UI (checking the box).
I get across this problem all the time and I cant think of any other
solution than setting a flag when changing some control's properties from
my
code.

That's the typical approach. You can utilize the checkbox's 'Tag' property
to store the flag.
 
Back
Top