Link to home
Start Free TrialLog in
Avatar of Binder
Binder

asked on

Array of "Private WithEvents" controls : How?

    I need to create an array of controls declared as "Private WithEvents".
     How can I do this?

     Restriction: I cannot put my controls in a form. I must create then
manually with Form.Controls.Add.

     Thanks
Avatar of Dalin
Dalin

I sort of remember you can't do that in vb5. I am not sure about vb6.
You can't do that in VB6 as well. sorry.
i agree, its not possible
Avatar of Binder

ASKER

Ooops. So maybe I came to a dead end here.
Or maybe there is another solution for this.

    I will be able to do what I want if:
       a) I can handle a collection of such objects
easily (i.e. without have to create one variable
for each and handle them separetely) OR
       b) I can guarantee that the controls inside
a form are created in a certain order that I can
choose. If this is possible then I can put
my controls in a form and create an array.
In order to create new controls on a form you must place at least one of each type of control on the form with an Index of 0. Then when you try to access controls in this control array with an index of > 0, VB will automatically add the controls for you. The only drawback is you have to have at least one of the controls on the form in order to implement dynamic control creation.
Avatar of Binder

ASKER

 Yes, but I can't have any controls on the
form because I need the controls to be created
in a certain order.
You could have the initial control of each type be Visible = False and Enabled = False. This would allow the control to essentially not exist to the user.

The fact remains that in order to do dynamic control creation in VB you MUST have at least one of each type of control on the form. If this is not an acceptable solution then you simply can't use VB to code you application.
Prozak, as I think Binder knows, seems to have the wrong end of the stick - it is possible to do dynamic control creation in VB6, and very useful it is too - just look up "what's new in controls" in the help.

What Binder's asking for is a way of sinking events generically from all the controls he's added.

hmmm, how many points is this question?

.... OK I'll be nice, let me go away for 20 mins or so, and create a couple of useful classes for you...

Ahhh, It's all becoming clear now... Thanks for the info andyclap. I was not aware of the VBObjectExtender object. I stand corrected, my understanding was that dynamic control creation was implemented by have a control array for each type and simply loading the next control in the control array would add a new control to the form. This would probably still yield better performance than the late-bound implementation using the VBObjectExtender but if it is precluded by the requirement of no controls then so be it.
ASKER CERTIFIED SOLUTION
Avatar of andyclap
andyclap
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Binder

ASKER

What can I say?

Thank you!!! :)

May the Force be with you... No! wrong
speech!

Let's try again:
May your karma lead you to happiness.