Solved

Handling / creating events for run-time created controls

Posted on 2004-08-02
4
265 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 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