Results 1 to 3 of 3

Thread: [02/03] Dynamic Controls

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2004
    Location
    Chennai,India
    Posts
    40

    Thumbs up [02/03] Dynamic Controls

    I have number of text boxes in a Windows form

    textbox1,textbox2,textbox3 etc.

    I want to retrieve the values from these textboxes dynamically

    like => Dim txt as textbox

    for i = 1 to 3
    txt.name = "textbox" & i
    msgbox txt.text
    next

    This is not working. Can you please help.
    Thanks

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: [02/03] Dynamic Controls

    put the textboxes in an array
    textboxes(0), textboxes(2), textboxes(2) .
    Then use
    VB Code:
    1. For I = 0 To 2
    2.      MsgBox (textboxes(i).Text)
    3. Next
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: [02/03] Dynamic Controls

    Or just loop through the controls and check if it is a Textbox
    VB Code:
    1. For Each cTemp As Control In Me.Controls
    2.             If TypeOf (cTemp) Is TextBox Then
    3.                 MessageBox.Show(cTemp.Text)
    4.             End If
    5.         Next
    Use [code] source code here[/code] tags when you post source code.

    My Articles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width