Runtime, array of controls events

  • Thread starter Thread starter vbMark
  • Start date Start date
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
 
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
 
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
 
vbMark

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

I hope this helps?

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

Thanks!
 
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.
 
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

Back
Top