473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Changing control value without triggering an event.

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.
Nov 15 '05 #1
1 3798
hmmm....

Honestly, I'd probably go with the boolean value, or some other method to
check when to truly modify your data. You either subscribe to event, and
you have it, or you don't. Can't straddle the fence with this one. If you
Never want the event use -= to unsubscribe. If you want it sometimes,
subscribe to it and activate it's code only based on your business'
conditions.

Nick Harris, MCSD
http://www.VizSoft.net

"Wavemaker" <ja**********@BiteMeHotmail.com> wrote in message
news:wJ_Kb.769908$Tr4.2209716@attbi_s03...
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.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: mike | last post by:
I have some elements that I want to change color when I mouse over them and them back on mouse off. I'd like the color to remain with "#c7d0e0" when the user clicks on them. <td...
1
by: OhFiddleSticks | last post by:
Does anyone know if there is a way to add a text value to a combo box (the text box part, not the rowsource) in VBA without triggering an update event? I've tried everything I can think of without...
2
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the...
1
by: Vern | last post by:
I know that I can get it to run but setting the focus to that control, and then to another control that causes validation, but I'm wondering if I can trigger that event for a control without using...
1
by: Adrian Parker | last post by:
At postback time, the controls are all recreated before an event fires. If the event determines that some of the controls need to be replaced with different controls that you can't create as...
9
by: Brian | last post by:
Hello - I have created a handler as follows that, when fired, will set a boolean value to True/False: AddHandler DirectCast(ctl, TextBox).TextChanged, AddressOf ControlIsDirty Private Sub...
2
by: Manuel | last post by:
When a form loads it fires all modification events for its controls. For example, if I put a comboBox and give it some values at design time, it will fire the comboBox_Change event (or whatever it...
13
by: mirandacascade | last post by:
I want to set things up such that a section of code will have been executed by the time one clicks on the drop down arrow on a combo box control. Currently, that section of code resides in the...
3
by: Allen Chen [MSFT] | last post by:
Hi Richard, Quote from Richard================================================== However I also want to be able to remove the panes. I have tried to include this, but find that when I first...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.