Is there an event that fires when . . .

smo06

New member
Joined
Nov 30, 2006
Messages
1
Programming Experience
Beginner
Hello,
I have a tabbed form that contains hundreds of controls. Way to many to program a _valueChanged event
for every single one of them. Is there a form or tab level event that keeps track of its child controls and whether or not their value property has changed ?
All i want to do is flip a boolean if a control's (any control) value has changed.
If you have a simple way to do this I would be obliged if you would share it.

Thank you very much,
Shawn
 
How about

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] m_isChange [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Boolean[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#0000ff]False[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] TextBox_TextChanged([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) _[/SIZE]
[SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged, TextBox5.TextChanged, TextBox6.TextChanged, TextBox7.TextChanged, TextBox8.TextChanged, TextBox9.TextChanged, TextBox10.TextChanged[/SIZE]
[SIZE=2]m_isChange = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
It is very easy to create an event handler for multiple controls in VB 2005. Select all the controls in the designer, then go to the Properties window and press the Events button. You can double-click the desired event to have the IDE generate an event handler for you, which will contain every selected control in the Handles clause (as lingsn has shown), or else you can select an existing event handler from the drop-down list.
 
You can also do it at run-time, by looping through all controls (will need to do it recursively if you have and container objects (panels, tabs, etc)) and use AddHandler to add a handler to the control's Changed event and point it to a sub set up to handle the event.

-tg
 
Back
Top