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
Printable View
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
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
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
Sorry clicked too fast
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