I was wondering if there is a way to change the value of a control
without triggering an event. The ComboBox control, for example, will
trigger the SelectedIndexChanged event when its SelectedIndex
property is changed. I would like to change the SelectedIndex
property without triggering an event.
The reason I ask is that in the application I'm writing, I have many
controls that manipulate the program data. The data is encapsulated
into a model class to keep it separate from the gui portion of my
app. When a control's value changes and its corresponding event is
triggered, the model is modified.
Control ---> Model
So far so good. But sometimes the model can change without the
control, in which case the control will need to be updated to
accurately represent the model. Sticking with the ComboBox example,
this would mean changing its SelectedIndex property, but doing so
causes the SelectedIndexChanged event to trigger thus modifying the
model needlessly. So I wind up with a circular situation.
Control <--- Model
Control ---> Model
Any thoughts of a way around this? A better design, maybe?
The easy answer is for the delegate representing the method to
handle the control's event to be removed before the control is
changed and then added again afterwards. Or maybe a boolean variable
indicating to the event handler if it should modify the model. At
any rate, I'd appreciate any thoughts. Thanks.