0

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".

Edited by __avd: Added [code] tags.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by wannasee
0

Yes you can.

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

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.