
Events for dynamically added controls
Hi,
may you create TextBox and ComboBox Ctrls.
create a new UserControl and place a TextBox on it
create a new UserControl and place a ComboBox on it
add a function to a module:
Public Function ControlActivate(CtrlType as Long, CtrlName as String) as
Variant
select case CtrlType
case 0
'TextBox Change
case 1
'ComboBox Click
end select
End Sub
add a eventproc to the newly createt usercontrols:
Private Sub TextBox1_Change()
Result = ControlActivate(0,UserControl.Extender.Name)
End Sub
Private Sub ComboBox1_Click()
Result = ControlActivate(1,UserControl.Extender.Name)
End Sub
extended ideas:
may you provide a ActionType as paramater for ControlActivate (Click,
Change, DropDown.........)
instead of CtrlName you can use Ctrl as Object to manipulate properties
Public Function ControlActivate(CtrlType as long, Ctrl as Object,
ActionType as Long)
select case CtrlType
case 0
select case ActionType
case 0 'Change
case 1 'LostFocus
if ctrl.text = "Hello" then
ControlActivate = "World"
end if
...
...
end Function
private sub TextBox1_Change()
Result = ControlActivate(0,UserControl.TextBox1,0)
end sub
private sub TextBox1_LostFocus()
Result = ControlActivate(0,UserControl.TextBox1,1)
end sub
to add the controls:
Controls.Add new CtrlTextBox,"TextBox" & mintNumTextBoxesAdded, fraFrame
regards
Quote:
> Hi,
> I am adding controls to a form dynamically
> e.g. Set txtboxObj = Controls.Add("VB.TextBox", "txtboxObj" &
> mintNumTextBoxesAdded, fraFrame)
> The code to add the control is part of a loop so I cannot know at design
> time how many controls will be onthe form during run time.
> I want to change a variable (blnIsDirty) when the user fires a change even
t
> in any of the text boxes that I have added.
> How can I add the events for the controls I am adding. I think if I use a
> VBControlExtender object I can use the ObjectEvent event. But what about
if
> I am using the method above?
> How can I add a Change event for every text box and a click event for
every
> combo box I've added.
> Any help much appreciated,
> Thanks,
> Jonathan