You probably figured this out by now but for anyone else with the same or similar problem looking for the old VB6 control array then you need to delegate the Event to a helper method.
The helper method must have the same signature as the event being delegated
Usually along the lines of “Event Name”
(ByVal sender As Object, ByVal e As System.EventArgs)
to demonstrate create a new windows project and add 4 radio buttons to the form or another control if you prefer( Alter the code to suit )
and add the following code to the form
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler RadioButton1.Click, AddressOf RadioChanged
AddHandler RadioButton2.Click, AddressOf RadioChanged
AddHandler RadioButton3.Click, AddressOf RadioChanged
AddHandler RadioButton4.Click, AddressOf RadioChanged
End Sub
Private Sub RadioChanged(ByVal sender As Object, ByVal e As System.EventArgs)
MsgBox(CType(sender, RadioButton).Name)
End Sub
OK this a bit useless as most people would not use radiobuttons in this manor
Add a number of textboxes to the form about 10 would be ok
Then add this code to the form load event
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is TextBox Then
AddHandler ctrl.Validating, AddressOf ValidateTextFields
End If
Next
ctrl.Dispose()
ctrl = Nothing
and add this method
Private Sub ValidateTextFields(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
e.Cancel = CType(sender, TextBox).Text = String.Empty
If e.Cancel = True Then
MessageBox.Show("TextField " & CType(sender, TextBox).Name & " Must Be Completed", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
You should now have a simple ( all be it poor for user input, but it is only a demo of a concept) validation on all textboxes
Why not add it to the handles clause of the first textboxes validation event
Like
Private Sub TextBox1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Handles TextBox1.Validating, TextBox2.Validating
End Sub
This will work but you can not remove the handler at a later stage Add the following to the ValidateTextFields method after the previous if statement
If CType(sender, TextBox).Name = "TextBox1" Then
RemoveHandler TextBox1.Validating, AddressOf ValidateTextFields
End If
This should remove the handler and the validation
I Hope this helps
Cheers
James