Runtime, array of controls events

V

vbMark

I have the following code:

Dim myTextBox(10) As TextBox

Dim x As Integer
For x = 0 To 9

myTextBox(x) = New TextBox
With myTextBox(x)
Select Case x
 
P

Pipo

Hi vbMark,

I dont see the events OnFocus or Onchange for a textbox.
But in general you create an addhandler for the events you'll need.

Hope this helps
 
V

vbMark

Sorry, I meant GotFocus and TextChanged.


Hi vbMark,

I dont see the events OnFocus or Onchange for a textbox.
But in general you create an addhandler for the events you'll need.

Hope this helps
 
C

Cor Ligthert

vbMark

\\\
For Each ctr as TextBox In myTextBox
AddHandler ctr.GotFocus, AddressOf meGotFocus
AddHandler ctr.TextChanged, AddressOf meTextChanged
Next
///

I hope this helps?

Cor
 
V

vbMark

I think addhandler may be what I'm looking for. First tests look good.
I'll contine trying it out.

Thanks!
 
V

vbMark

vbMark

\\\
For Each ctr as TextBox In myTextBox
AddHandler ctr.GotFocus, AddressOf meGotFocus
AddHandler ctr.TextChanged, AddressOf meTextChanged
Next
///

I hope this helps?

Cor

Ok, using AddHandler works and creates the event. Now how do I know which
control in the array fired the event?

I have this in my loop:
AddHandler myTextBox(x).GotFocus, AddressOf myTextBox_GotFocus

And this Sub:
Sub myTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
????
End Sub

Thanks.
 
C

Cor Ligthert

vbMark,

In this situation I gave every control a name before I add them to the form.

\\\
myTextBox.Name=x.ToString
Me.Controls.Add(myTextBox(x))
///

Then you can do by instance in the event

\\\
Sub myTextBox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
Select Case DirectCast(sender,TextBox).Name
Case "0"
'do something
Case "1"
End Sub
///

I hope this helps?

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top