Events for dynamically added controls 
Author Message
 Events for dynamically added controls

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 event
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



Tue, 23 Jul 2002 03:00:00 GMT  
 Events for dynamically added controls
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 event
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



Tue, 23 Jul 2002 03:00:00 GMT  
 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



Tue, 23 Jul 2002 03:00:00 GMT  
 Events for dynamically added controls
Put your textbox in a control array (for example, txtBox(0),
txtBox(1),etc...)

Then code the Change event of the txtBox.  If you need to access any
particular textbox use its index.


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
event
> 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



Tue, 23 Jul 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Adding Events to Dynamically Added Controls

2. Events for dynamically added controls

3. How to handle an event fired from a control that was added dynamically

4. Problem with dynamically added controls and events

5. Best practises for dynamically adding and removing event handlers

6. adding onclick events to dynamically created menu items

7. Dynamically Adding Event Handlers

8. Try to handle Enter, Exit events for a TextBox added dynamically (use Withevents)

9. Dynamically adding controls to the Controls collection

10. Dynamically add controls to a control array

11. Adding Controls Dynamically To SSTab Control

12. Dynamically adding controls to an SSTab control

 

 
Powered by phpBB® Forum Software