user867621
user867621

Reputation: 1197

Is there a way to watch multiple textboxes to see if the text changed?

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

Answers (4)

MarcinJuraszek
MarcinJuraszek

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

user1278274
user1278274

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

Coltech
Coltech

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

Steve
Steve

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

Related Questions