Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic TextBox's on Form (Array)

Status
Not open for further replies.

Trob70

Programmer
Sep 25, 2012
89
AU
I am converting a vb6 program to vb.net

in vb6 i am using the following code to generate 25 Textboxes down the page , under eachother, dynamically using F1(0) as the starting position
ir F1(1), F1(2) etc up to 25


??? is there a way of doing this in vb.net


Really appreciate some help

----------------------------------------------------------------

Fld = "F1" 'ie it's a textbox

NumRows = 25
NumCols = 1

With Controls(Fld)(0)
GridTop = .Top
GridLeft = .Left
CellHeight = .Height
CellWidth = .Width
.Visible = False
.Enabled = False
End With

For Idx = 1 To (NumCols * NumRows)
Load Controls(Fld)(Idx)
With Controls(Fld)(Idx)
.Move GridLeft + ((Idx Mod NumCols) * CellWidth), GridTop + ((Idx \ _
NumCols) * CellHeight)
.Visible = True
.Enabled = True

End With

Next Idx 'Idx

Next ll
 
In VB.NET you don't have arrays of controls in the sense as the VB6 does, but you can still add controls on your Form at run time (Google is your friend)

In addition you can have a Button, RadioButton and CheckBox all in the same 'array' of controls if you want to. :) You don't have to be 'limited' to just one type of control to create an 'array' from.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Andy.. Thanks for your post re my problem..

After a lot of searching I found this solution to add controls as an array it seems to work all ok

Dim Array_Size As Integer = 5
Dim rb_(Array_Size)
For i = 0 To Array_Size
rb_(i) = New TextBox
rb_(i).Text = "TB" + i.ToString
rb_(i).Top = 20 * i
Me.Controls.Add(rb_(i))
Next

MsgBox(rb_(2).text)

Regards Trob70
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top