Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Textbox Array

Textbox Array

Scheduled Pinned Locked Moved Visual Basic
helpcsharpdatabasevisual-studio
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    parth p
    wrote on last edited by
    #1

    Hi, I am stuck on VB.NET 2005, in VB6 i was able to load objects at run-time. Problem is I am asking user how many textboxes they want and then system will create an array of those textboxes. Here's the code I was using in VB6. I already had one textbox on form and the index was set to 0.(can't even do that vb.net):confused:

    For i = 1 to iSelectedNum
             Load TextBox(i)
             TextBox(i).Visible = True
             TextBox(i).Top = TextBox(i - 1).Top + TextBox(i - 1).Height
             TextBox(i).Left = TextBox(i - 1).Left
             TextBox(i).Text = ""
    Next i
    

    I tried Code Upgrade function from VS 2005 but did not worK!!! Anyone please HELP!! :sigh:

    D 1 Reply Last reply
    0
    • P parth p

      Hi, I am stuck on VB.NET 2005, in VB6 i was able to load objects at run-time. Problem is I am asking user how many textboxes they want and then system will create an array of those textboxes. Here's the code I was using in VB6. I already had one textbox on form and the index was set to 0.(can't even do that vb.net):confused:

      For i = 1 to iSelectedNum
               Load TextBox(i)
               TextBox(i).Visible = True
               TextBox(i).Top = TextBox(i - 1).Top + TextBox(i - 1).Height
               TextBox(i).Left = TextBox(i - 1).Left
               TextBox(i).Text = ""
      Next i
      

      I tried Code Upgrade function from VS 2005 but did not worK!!! Anyone please HELP!! :sigh:

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Control arrays don't exist under VB.NET. However, you can create your own quite easily.

      Dim myTextBoxes As New List(Of TextBox)
      For i = 1 to iSelectedNum
          Dim newTextBox As New TextBox()
          With newTextBox
              .Top = _calculated Top value_
              .Left = _calculated Left value_
              .Text = "_whatever text you want_"
          End With
          myTextBoxes.Add(newTextBox)
          Me.Controls.Add(newTextBox)
      Next
      

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007

      P 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Control arrays don't exist under VB.NET. However, you can create your own quite easily.

        Dim myTextBoxes As New List(Of TextBox)
        For i = 1 to iSelectedNum
            Dim newTextBox As New TextBox()
            With newTextBox
                .Top = _calculated Top value_
                .Left = _calculated Left value_
                .Text = "_whatever text you want_"
            End With
            myTextBoxes.Add(newTextBox)
            Me.Controls.Add(newTextBox)
        Next
        

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        P Offline
        P Offline
        parth p
        wrote on last edited by
        #3

        Thanks a lot Dave. But there's one more question now!? How can i access them (textboxes)?

        D 1 Reply Last reply
        0
        • P parth p

          Thanks a lot Dave. But there's one more question now!? How can i access them (textboxes)?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4
          Private myTextBoxes As List(Of TextBox)
          
          ....
          
          Private Sub CreateTextBoxes(ByVal count As Integer)
              myTextBoxes = New Dictionary(Of String, TextBox)
              For i As Integer = 1 To count
                  Dim newTextBox As New TextBox
                  With newTextBox
                      .Top = i \* 20
                      .Left = 10
                      .Size = New Size(100, 18)
                  End With
                  myTextBoxes.Add(newTextBox)
                  Me.Controls.Add(newTextBox)
              Next i
          
              ...
          
              myTextBoxes(6).ForeColor = Color.Blue
          

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007

          P 1 Reply Last reply
          0
          • D Dave Kreskowiak
            Private myTextBoxes As List(Of TextBox)
            
            ....
            
            Private Sub CreateTextBoxes(ByVal count As Integer)
                myTextBoxes = New Dictionary(Of String, TextBox)
                For i As Integer = 1 To count
                    Dim newTextBox As New TextBox
                    With newTextBox
                        .Top = i \* 20
                        .Left = 10
                        .Size = New Size(100, 18)
                    End With
                    myTextBoxes.Add(newTextBox)
                    Me.Controls.Add(newTextBox)
                Next i
            
                ...
            
                myTextBoxes(6).ForeColor = Color.Blue
            

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007

            P Offline
            P Offline
            parth p
            wrote on last edited by
            #5

            Thanks for Reply. But there is still one problem in the example of code you wrote, and i cant figure it out why is it happening. It gives me following error

            "Error1 -> Value of type 'System.Collections.Generic.Dictionary(Of String, System.Windows.Forms.TextBox)' cannot be converted to 'System.Collections.Generic.List(Of System.Windows.Forms.TextBox)'."
            myTextBoxes = New Dictionary(Of String, TextBox)

            D 1 Reply Last reply
            0
            • P parth p

              Thanks for Reply. But there is still one problem in the example of code you wrote, and i cant figure it out why is it happening. It gives me following error

              "Error1 -> Value of type 'System.Collections.Generic.Dictionary(Of String, System.Windows.Forms.TextBox)' cannot be converted to 'System.Collections.Generic.List(Of System.Windows.Forms.TextBox)'."
              myTextBoxes = New Dictionary(Of String, TextBox)

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Sorry, my mistake. That line should be:

              myTextBoxes = New List(Of String)
              

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups