4 Replies - 297 Views - Last Post: 30 August 2011 - 03:25 PM Rate Topic: -----

#1 wannasee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-August 11

How do I add a newly created textbox to a dynamic Textbox array

Posted 30 August 2011 - 06:01 AM

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

This post has been edited by modi123_1: 30 August 2011 - 06:37 AM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: How do I add a newly created textbox to a dynamic Textbox array

#2 Luc001  Icon User is offline

  • D.I.C Addict

Reputation: 84
  • View blog
  • Posts: 617
  • Joined: 04-May 09

Re: How do I add a newly created textbox to a dynamic Textbox array

Posted 30 August 2011 - 06:36 AM

Hi,

You could do something like this:

Dim number As Integer = 10
Dim textBoxes(number) As TextBox
For i = 0 To number
textBoxes(i) = New TextBox
textBoxes(i).Top = i * TextBoxes(i).Height
Controls.Add(TextBoxes(i))
Next

Was This Post Helpful? 0
  • +
  • -

#3 kingsonprisonic  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 74
  • Joined: 09-July 09

Re: How do I add a newly created textbox to a dynamic Textbox array

Posted 30 August 2011 - 09:01 AM

See this

http://www.daniweb.c.../threads/379872
Was This Post Helpful? 0
  • +
  • -

#4 wannasee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 22-August 11

Re: How do I add a newly created textbox to a dynamic Textbox array

Posted 30 August 2011 - 09:43 AM

That snippet of help doesn't work. Just get the error
"Object cannot be stored in an array of this type."
Was This Post Helpful? 0
  • +
  • -

#5 trevster344  Icon User is offline

  • The Peasant
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,501
  • Joined: 16-March 11

Re: How do I add a newly created textbox to a dynamic Textbox array

Posted 30 August 2011 - 03:25 PM

Build your objects and place them in a List(Of T) maybe?

I'm not sure if that would work correctly, but it's worth a shot.
http://msdn.microsof...y/6sh2ey19.aspx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1