|
-
Dec 31st, 2003, 04:01 AM
#1
Thread Starter
Junior Member
Events handling with runtime created controls {RESOLVED}
I have a set of runtime created combo boxes which i keep in a collection.
How do I use withevents or any other method to keep track of the selection changes made to these combo boxes?
Thanks in advance
Last edited by weiyen; Jan 14th, 2004 at 08:14 PM.
-
Jan 2nd, 2004, 03:34 AM
#2
-= B u g S l a y e r =-
think you can do something like this
VB Code:
Private WithEvents MyListBox As ListBox
Private Sub Form_Load()
Set MyListBox = Me.Controls.Add("VB.ListBox", "lstNewListBox")
With MyListBox
.Move 0, 0, 800, 2000
.Visible = True
End With
End Sub
-
Jan 2nd, 2004, 03:37 AM
#3
-= B u g S l a y e r =-
VB Code:
Option Explicit
Private WithEvents MyListBox As ListBox
Private Sub Form_Load()
Dim i As Integer
Set MyListBox = Me.Controls.Add("VB.ListBox", "lstNewListBox")
With MyListBox
.Move 0, 0, 800, 2000
.Visible = True
End With
For i = 0 To 100
MyListBox.AddItem "item " & Format(i, "000")
Next i
End Sub
Private Sub MyListBox_Click()
MsgBox MyListBox.Text
End Sub
-
Jan 2nd, 2004, 08:14 AM
#4
Thread Starter
Junior Member
Last edited by weiyen; Jan 2nd, 2004 at 08:19 AM.
-
Jan 2nd, 2004, 08:17 AM
#5
Thread Starter
Junior Member
Thank you for the replies.
The method you had given needs to have multiple declarations of withEvents for each control created during runtime.
I've discovered that I can declare a class of event handlers.
Can't really remember the codes, as i left it in my office, but it goes something like this..
(Class: comboEvent)
Public withEvents myCombo as comboBox
Private Sub myCombo_Change()
msgBox myCombo.text
End Sub
(Usage)
Dim comboHandler as comboEvent
Dim eventCollection as collection
Dim comboCollection as collection
Set eventCollection = new collection
Set comboCollection = new collection
Private Sub CommandButton1_Click()
set comboHandler as new comboEvent
eventCollection.AddItem comboHandler
comboCollection.AddItem Controls.add(ComboBox,,,) ' Can't remeber exact codes here.
Dim ctrl as comboBox
Dim i as integer
for each ctrl in comboCollection
set eventCollection.item(i).myCombo = comboCollection.item(i) 'Can only remember its something like this. Will provide the working set on monday (Singapore time)
next ctrl
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|