Solved

Dynamically adding controls to a Collection

Posted on 2006-11-03
1
256 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 86

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 42
Help with opening combobox using VB.NET. 3 38
Telerik RadEditor Control Save 8 20
vb.net datagrid point 4 23
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

730 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