Solved

Dynamically adding controls to a Collection

Posted on 2006-11-03
1
242 Views
Last Modified: 2010-04-23
I need to dynamically (at run time) create a large amount of textboxes.  I want to create a loop which adds the controls (textboxes in this case) to a collection.  How can I do this?  I know I can loop through and create differest control names, text, etc., but I can't figure out how to use a loop to generate different actual controls.  As an example:

I tried this:

for i = 1 to txtBoxAmt
txtBoxCollection.add(textbox1) . . . . I can't modify "textbox1" using the count varible "i".  Any ideas?
textbox1.name = "name" & i"
textbox1.text = "text" & i"
Next

Please help.  THANKS!
0
Comment
Question by:mgb1000
1 Comment
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 17867199
Dim tb As TextBox
For i As Integer = 1 To txtBoxAmt
    tb = New TextBox
    tb.Name = "Name" & i
    tb.Text = "Text" & i
    txtBoxCollection.add(tb)
Next
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question