Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trapping Events for runtime created controls 3

Status
Not open for further replies.

granni

Programmer
Nov 8, 2000
36
SG
i have controls created at runtime using
Me.Controls.Add("VB.CommandButton","CommandNew",me)

Now i have a piece of VB code in a string variable e.g. "Msgbox Hello", how do i place this string behind the Click event of this new button?

Can anyone help?
 
When you added the control dynamically, you had to already have a copy of it present on the form, right? (otherwise the dynamically added control won't appear). When you do this, you're creating a control array. You would then put code in the "master" copy of the button, and based on the control's index or caption property, you'd do your specific stuff.

Chip H.
 
What Chip is referring to is a control array . . . they will do exactly what you want and they are easy to use. But they do require that you have a least one control of the type you want to programatically add on the form at runtime.
Another option is to do exactly what you are doing now and store the reference to the newly created control in a class wrapper that has event sinks set up for the control that you are working with (simply delcare a private instance on the control with events inside of the class object).
Either of these methods will allow you to catch the fired events. - Jeff Marler B-)
 
Thanks man for the sugeestion, i using it now
Thanks again :> In Christ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top