Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Handling / creating events for run-time created controls

Posted on 2004-08-02
4
Medium Priority
?
271 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

886 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