• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 439
  • Last Modified:

How to detect events on a textbox array created programaticly?

I have cretaed an array of textbox objects programaticly on Visual Basic 2008.

Now I need to detect when somebody clicks on one of those textboxes.

Can you Help me pls?
0
RUIDEOLIVEIRA
Asked:
RUIDEOLIVEIRA
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
As you create each TextBox use AddHandler() to "wire up" the Click() event to a handler.

Make sure you're using the correct event....not sure if you literally want the Click() event or if you actually need the MouseDown() or the GotFocus() events?

At any rate, you can follow this example and adjust the event and signature as necessary:
Public Class Form1

    Private TextBoxes As New List(Of TextBox)

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For i As Integer = 1 To 10
            Dim tb As New TextBox
            tb.Name = "MyTextBox" & i
            tb.Text = "TextBox #" & i
            AddHandler tb.Click, AddressOf TB_Click
            FlowLayoutPanel1.Controls.Add(tb)
            TextBoxes.Add(tb)
        Next
    End Sub

    Private Sub TB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim TB As TextBox = CType(sender, TextBox)
        MessageBox.Show("TextBox Name: " & TB.Name & vbCrLf & "TextBox Text: " & TB.Text)
    End Sub

End Class

Open in new window

0
 
RUIDEOLIVEIRAAuthor Commented:
The problem is completely solved.
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now