Solved

How to detect events on a textbox array created programaticly?

Posted on 2010-09-22
2
431 Views
Last Modified: 2012-08-13
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
Comment
Question by:RUIDEOLIVEIRA
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 50 total points
ID: 33734095
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
 

Author Closing Comment

by:RUIDEOLIVEIRA
ID: 33736254
The problem is completely solved.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
commandline.codeplex.com required argumen except when displaying help 2 45
Need example 5 116
VS2015 compilation and missing DLLs 9 148
Build VS2015 project in bat command 3 89
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question