Solved

Handling / creating events for run-time created controls

Posted on 2004-08-02
4
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

632 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