[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 282
  • Last Modified:

Dynamically adding controls to a Collection

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
mgb1000
Asked:
mgb1000
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now