Reputation: 1197
I have about 15 text boxes and instead of going to the event handler on each one and enabling a button on a change..
For example:
Private Sub txtIsbnUpc_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles txtIsbnUpc.TextChanged
cmdSearchresults.enabled = true
End Sub
Instead of going through each one and typing that is there a simpler way?
Upvotes: 0
Views: 2505
Reputation: 125630
Why don't you extend the Handles
list and handle all textBoxes events in one handler?
Private Sub txtIsbnUpc_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _
Handles txtIsbnUpc.TextChanged, txt2.TextChanaged, txt3.TextChanged
You can use sender
to check which textBox fired that handler, if it's needed for your logic.
Upvotes: 3
Reputation: 21
you can even use addhandler for each text box and lead it to other function created by you with argument to text change of textbox....
Upvotes: 0
Reputation: 1710
Yes, list your other textboxes in the "Handles" section of your event signature:
Private Sub txtIsbnUpc_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtIsbnUpc.TextChanged, Handles txt2.TextChanged,Handles txt3.TextChanged, etc....
sender.enabled = true
End Sub
Upvotes: 0
Reputation: 216293
One of the beauty of .NET is the ability to wire the same event handler to more than one control.
You could assign the same handler to the TextChanged event of all your 15 textbox.
So no need to code 15 event handler with the same code.
Upvotes: 1