CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2010
    Posts
    6

    Unhappy How to get the TEXT values Entered in Text boxes Dynamically.???

    Hello everybody..... i'm having the following code to add the textboxes dynamically.... now i want to get the values entered in that textboxes dynamically..... PLS HEPL ME OUT....


    heres the code:

    Code:
    Public Class Form1
        Public x = 17
        Public y = 60
        Public Num As Integer
        Public sNum As String
        Private Sub frmDynamic_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            sNum = InputBox("No of File to be uploaded...?", "FTP-Up Load", "", )
            Me.ForeColor = Color.Black
            Me.BackColor = Color.AliceBlue
            If Integer.TryParse(sNum, Num) Then
                addTxtToMe(Num)
                Button1_mousemove()
            Else
                MessageBox.Show("App Quits!!! You did not enter a valid number")
                End
            End If
    
        End Sub
        Public Sub addTxtToMe(ByVal Num As Integer)
            For counter As Integer = 1 To Num
                Dim txt As New TextBox()
                txt.Name = "txtDynamic" & counter
                txt.Location = New Point(x, y)
                txt.Size = New Size(190, 25)
                Me.Controls.Add(txt)
                y = y + 25
                If y > 555 Then
                    x = x + 210
                    y = 5
                End If
            Next
        End Sub
        Private Sub Button1_mousemove()
            Button1.Name = "butDynamic"
            Button1.Text = "Submit"
            Button1.Location = New Point(x, y)
            Button1.Parent = Me
        End Sub
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            'For counter As Integer = 1 To Num
            '    Dim i = 1
            '    If Not txt.Text Is Nothing Then
            '        Do
            '            End
            '        Loop
            '    End If
    
            'Next
        End Sub
    End Class



    Pls figure out the mistakes n corrections.....


    THANKS IN ADVANCE...........
    Last edited by HanneSThEGreaT; February 18th, 2010 at 02:56 AM.

  2. #2
    Join Date
    Jan 2010
    Posts
    38

    Re: How to get the TEXT values Entered in Text boxes Dynamically.???

    Code:
            For Each ctl As Control In Me.Controls
                'if textbox
                If TypeOf ctl Is TextBox Then
                    'This assumes that all entries are string/text (Not dates, Numeric, Boolean etc.)
                    strData = ctl.Text.ToString()
                End If
            Next
    This snippet originally supplied by Cimperiali
    Last edited by ddclondon; February 18th, 2010 at 12:38 AM.

  3. #3
    Join Date
    Feb 2010
    Posts
    6

    Smile Re: How to get the TEXT values Entered in Text boxes Dynamically.???

    [QUOTE=ddclondon;1918411][code]
    THANKX ALOT................

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: How to get the TEXT values Entered in Text boxes Dynamically.???

    prince_XY143, please remember to use Code tags when posting code, as explained here :

    http://www.codeguru.com/forum/showthread.php?t=403073

    Thank you

    Hannes

  5. #5
    Join Date
    Jan 2010
    Posts
    38

    Re: How to get the TEXT values Entered in Text boxes Dynamically.???

    Your code:


    Code:
                Dim txt As New TextBox()
                txt.Name = "txtDynamic" & counter
                txt.Location = New Point(x, y)
                txt.Size = New Size(190, 25)
                Me.Controls.Add(txt)
    If I were attempting this I would identify the textboxes dynamically while using the Tag property - the following code is typed manually here within this message so please excuse any typos:

    Code:
        Select Case Counter
            Case 1: txt.Tag = "Forename"
            Case 2: txt.Tag = "Surname"
            Case 3: txt.Tag = "Company"
            Case 4: txt.Tag = "Address1"
            Case 5: txt.Tag = "Address2"
            Case 6: txt.Tag = "Telephone"
        End Select
    Then, while retrieving the data you can be more specific as to which piece of data you are accessing by referring to the Tag property rather than the arbitrary name property you are using now.

    Code:
            For Each ctl As Control In Me.Controls
                'if textbox
                If TypeOf ctl Is TextBox Then
                    'This assumes that all entries are string/text (Not dates, Numeric, Boolean etc.)
                    strField = ctl.Tag
                    strData = ctl.Text.ToString()
                    Select Case strField
                       Case "Forename":   ..........
                        .................
                        .................
                    End Select
                End If
            Next
    This is just an idea but I am trying to be helpful within the bounds of my own lack of experience with VS2008

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

Featured