I wanted to simply on click a button to add those newly created textboxes to an array of textboxes. Starting with those labeled "Address". But I am finding this very difficult. I am able to add those originally on the form into the array very easily. But am unable to add the newly created textboxes into the array.

Here is my code so far below.

Public Class Form1
Dim MyBoxes() As TextBox = {Address, UserName, Password}
Dim Numbox As Integer = 1

Sub CopyLayout(ByVal B As Integer)
'add new row
Dim cr As New UserControl1
cr.Left = 0
cr.Address.Name = "Address" & B
cr.Top = Me.Panel1.Controls.OfType(Of UserControl1).Count * cr.Height + 98
Me.Panel1.Controls.Add(cr)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Numbox = Numbox + 1
Call CopyLayout(Numbox)
ReDim Preserve MyBoxes(Numbox)
MyBoxes(Numbox) = Me.Panel1.Controls.Item("Address" & Numbox)
End Sub
End Class

Extra info:
UserControl1.vb simply contains three textboxes named approapriatly as "Address", "Username" and "Password".

Recommended Answers

All 2 Replies

Yes you can.

But first you have to declare the array as MyBoxs(100) as textbox

then use MyBoxs.setValue(<Textbox Control>,<index>)

I get the error "Object cannot be stored in an array of this type."

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.