Solved

Handling / creating events for run-time created controls

Posted on 2004-08-02
4
260 Views
Last Modified: 2010-04-23
Hi guys,

I've got a form that creates several textboxes at run-time.  I've got an array of textboxes called Times(15).

Now, since these are created at run time, how am I able to determine, say, if the text was changed?  There is no text_changed event associated with it, since it wasn't created during design time.  So how am i able to associate events with these run-time created controls?

Thanks so much!

-Brad
0
Comment
Question by:bmvincent
  • 2
4 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11696122
you would use ...

textbox.text_changed+= new eventhandler(yourroutine)
0
 
LVL 14

Accepted Solution

by:
ptakja earned 100 total points
ID: 11696317
I believe gregoryyoung's comment is the C# syntax...

Since you created the textboxes at runtime, you need to "wire" the events to an event handler.   Try this:


    ' Loop through textboxes adding the single event handler for the TextChanged event
    For ii As Index = 0 To Times.Count -1
        AddHandler Time(ii).TextChanged, AddressOf TxtChanged
    Next

You can use the same technique to "wire" other textbox events to generic event handlers


    Public Sub TxtChanged(ByVal sender As Object, ByVal e As System.EventArgs)
           'Put your code here to deal with the txtChanged event
           You can determine the textbox in here by casting the sender object
          Dim txtBox As TextBox = CType(sender, TextBox)
         txtBox will be the textbox that triggered the event.          
    End Sub

Jeff
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11696332
oops you're right wrong forum :)

you are correct addhandler is the vb.net format/
0
 

Author Comment

by:bmvincent
ID: 11696371
Jeff, excellent response.  Makes alot more sense now.  I appreciate it.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now