Hi!
I'm trying to add in the form of a number of dynamic controls.
Can we get from each control event when the user clicks on any of them?
Piece of code cClass1 :
Piece of code Form1:
When we add next class of controls, the event is not generated from the previous checkbox.
So, is there any way to receive events from all dynamically created checkboxes? If we do not initially know how many there will be.
I'm trying to add in the form of a number of dynamic controls.
Can we get from each control event when the user clicks on any of them?
Piece of code cClass1 :
Code:
Option Explicit
Private WithEvents ctlTextbox As VB.TextBox
Private WithEvents ctlCheckBox As VB.CheckBox
Public Event OnChange(ByVal Text As String)
Private Sub Change(ByVal Text As String)
RaiseEvent OnChange(Text)
End Sub
Public Property Set TextBox(rhs As TextBox)
Set ctlTextbox = rhs
End Property
Public Property Get TextBox() As TextBox
Set TextBox = ctlTextbox
End Property
Public Property Set CheckBox(rhs As CheckBox)
Set ctlCheckBox = rhs
End Property
Public Property Get CheckBox() As CheckBox
Set CheckBox = ctlCheckBox
End Property
Private Sub ctlCheckBox_Click()
Call Change("clatz")
End Sub
Code:
Option Explicit
Public WithEvents cls As cClass1
Private Sub cls_OnChange(ByVal Text As String)
Debug.Print Text
End Sub
Code:
Private Sub Form_Load()
Dim n as Integer
For n=0 to <Random Count>
Set cls = New cClass1
Set cls.TextBox = Controls.Add("VB.TextBox", "txt" & n, Form1)
Set cls.CheckBox = Controls.Add("VB.CheckBox", "chk" & n, Form1)
Next
End Sub
So, is there any way to receive events from all dynamically created checkboxes? If we do not initially know how many there will be.