kevp75
asked on
How to add click event to dynamic control...
I have some label controls being added to my form at runtime. What I need to do now is to add/detect/get the click event for each label.
Anyone know how I can do this? (I'm a web developer by trade, but really have only dealt in scripting languages...)
Here's my code...
Anyone know how I can do this? (I'm a web developer by trade, but really have only dealt in scripting languages...)
Here's my code...
The dynamic controls are created as control array
so you can use as lblPageLinks_click()
Based on the index value you can perform task.
so you can use as lblPageLinks_click()
Based on the index value you can perform task.
ASKER
Private Sub lblPageLinks_Click()
MsgBox IsArray(lblPageLinks)
End Sub
does not do anything...
MsgBox IsArray(lblPageLinks)
End Sub
does not do anything...
make the breakpoint and check whether control is going there are not.
Private Sub lblPageLinks_Click()
MsgBox IsArray(lblPageLinks)
End Sub
Private Sub lblPageLinks_Click()
MsgBox IsArray(lblPageLinks)
End Sub
ASKER
Ok. Changed the code a little...
Also, added the breakpoints, and nothing happens
Also, added the breakpoints, and nothing happens
Private i As Integer
Private Sub Form_Load()
Dim lblPageLinks() As Variant
For i = 0 To 5
ReDim lblPageLinks(i)
Set lblPageLinks(i) = Controls.Add("VB.Label", "lContLinks" & i, Frame1)
With lblPageLinks(i)
.Visible = True
.AutoSize = True
.Left = 300
.Height = 300
.Top = 300 + (.Height * i)
.Caption = "Page Link " & i
.FontUnderline = True
.FontName = "Trebuchet MS"
.FontSize = 10
.ForeColor = &HFF0000
.MouseIcon = LoadPicture(App.Path & "\harrow.CUR")
.MousePointer = vbCustom
End With
Set lblPageLinks(i) = Nothing
Next
End Sub
Private Sub lContLinks_Click(Index As Integer)
MsgBox lContLinks(Index).Text
End Sub
ASKER
I also tried taking out the & i from Controls.Add line, figuring it would create it as an array, instead of simply 0-5 controls named lContLinks0 - lContLinks5
All that did was error out stating there was already a control with that name...
All that did was error out stating there was already a control with that name...
ASKER
knowing this.... the (lContLinks0 - lContLinks5) I would say it is not a control array...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well EE never posted the example in reference to the "Consider the following"
Dim Withevents Label1 As Label
Dim Withevents Label2 As Label
Dim Withevents Label3 As Label
Set Label1 = lblPageLinks(0)
Set Label2 = lblPageLinks(1)
Set Label3 = lblPageLinks(2)
ASKER
my concern is that I will never know how many of these labels need to be created. I will be pulling data from a database to populate this list of labels, and based on the query it can pull different number of records.
I will try the clone method you stated. Just set the originating label visibility to false so it does not show, and get back with the results...
I will try the clone method you stated. Just set the originating label visibility to false so it does not show, and get back with the results...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works a champ. Thanks!
ASKER
here it is, I promise!
Open in new window