SamJolly
asked on
How to insert Controls at a specific location within the Controls collection when building a dynamic table.
Hi,
I am building a dynamic table which contains multiple rows and each cell contains 7 cells. One of the cells has 2 textboxes. I want to add a label to that cell at runtime. Currently I am only using "add" so it is the last control in. How can I insert the label before the first TextBox?
At present I am doing
cells(6).controls.add(myLa bel)
If I want to add it before Textbox2 I do the following
cells(6).controls.Remove(T extbox1)
cells(6).controls.Remove(T extbox2)
cells(6).controls.add(myLa bel)
cells(6).controls.Remove(T extbox1)
cells(6).controls.add(Text Box2)
Is there not a better way of inserting a control at a specific location in the collection without removing controls?
Thanks,
Sam
I am building a dynamic table which contains multiple rows and each cell contains 7 cells. One of the cells has 2 textboxes. I want to add a label to that cell at runtime. Currently I am only using "add" so it is the last control in. How can I insert the label before the first TextBox?
At present I am doing
cells(6).controls.add(myLa
If I want to add it before Textbox2 I do the following
cells(6).controls.Remove(T
cells(6).controls.Remove(T
cells(6).controls.add(myLa
cells(6).controls.Remove(T
cells(6).controls.add(Text
Is there not a better way of inserting a control at a specific location in the collection without removing controls?
Thanks,
Sam
ASKER
carl,
thanks for this. So assuming I need to use 2 positions depending on Unit (£ or %) then the following would be correct?
If I had 2 textboxes2
TextBox1
Textbox2
then for "£" I would need :
cells(6).Controls.AddAt(0, myLabel)
and for "%" I would need:
cells(6).Controls.AddAt(2, myLabel)
Is my thinking and code correct?
Thanks,
Sam
thanks for this. So assuming I need to use 2 positions depending on Unit (£ or %) then the following would be correct?
If I had 2 textboxes2
TextBox1
Textbox2
then for "£" I would need :
cells(6).Controls.AddAt(0,
and for "%" I would need:
cells(6).Controls.AddAt(2,
Is my thinking and code correct?
Thanks,
Sam
ASKER
Actually for the "%" I can just do an "Add".
Sam
Sam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks, very helpful
Open in new window