You have to create a control array. Once you've done that, you can load more controls at runtime. For example, to add two textboxes:
Load textbox1(1)
Load textbox1(2)
To get rid of them:
Unload textbox1(2)
Unload textbox1(1)
Yep, if you have one textbox named txtMyText(0) and you want to create another one just like it, say Load txtMyText(1). This may not appear to work at first, because Visual Basic correctly assumes that you're going to want to move the new control before it's visible to the user. Once you've positioned the new control in its new location, be sure to call a txtMyText.Visible = True, and there it is.
The only problem you might run into is with properties you can't change at runtime. For example, I used this technique with listboxes, but I couldn't set the multiselect property at runtime for the dynamic controls I loaded. I had to have two seperate listbox control arrays, one that was single select and one that was multiselect.
The only question I have which I have not yet been able to find any documentation, or anything on is how to add an ARRAY of objects dynamically.
EX:
lblTime(0)
lblTime(1)
lblTime(2)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.