Data-GUI matching

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

Guest

Hi,

I am experiencing this problem all over again:
I pass some data to a form, so the form initializes its controls with this
data. Now when the user use these controls to change data I trap the event
and change the data so it is updated whit what the user selected from GUI.
The problem is that I want to trap the control's event (be it a click or
whatever) when the user changes it from GUI and I do NOT want to trap the
event when I change the control's value programatically. Otherwise when I
change it programatically, the event will fire, it will change data
programatically, the event will fire again etc.
I sovle this problem two ways:
1. Using flags but this is messy
2. Unsubscribing before changing control's value programatically and
subscribing
after that- I like this better but there is some run-time cost involved

Is there a better way to know how a control's value gets changed?

Thanks
 
Z said:
I am experiencing this problem all over again:
I pass some data to a form, so the form initializes its controls with this
data. Now when the user use these controls to change data I trap the event
and change the data so it is updated whit what the user selected from GUI.
The problem is that I want to trap the control's event (be it a click or
whatever) when the user changes it from GUI and I do NOT want to trap the
event when I change the control's value programatically. Otherwise when I
change it programatically, the event will fire, it will change data
programatically, the event will fire again etc.
I sovle this problem two ways:
1. Using flags but this is messy
2. Unsubscribing before changing control's value programatically and
subscribing
after that- I like this better but there is some run-time cost involved

Is there a better way to know how a control's value gets changed?

This is quite a common problem that I've been seeing less of in recent
years. Is there a better way? Well, many controls provide multiple usable
events these days, so it may well be possible to distinguish between a
change of the control data by the user and a change from code - you should
look at that for your controls.

As to using flags, if you only do it in the scenario you describe, you'd
need only one single flag "initializing", which you set while data is
first being loaded into the controls. If you need a flag per control, this
may of course become quite messy, that's right.

The reason I'm seeing less of this these days is that I usually use data
binding as much as possible, which gets rid of most of these problems. Any
reason you can't do that?


Oliver Sturm
 
Back
Top