Click to See Complete Forum and Search --> : How to get the TEXT values Entered in Text boxes Dynamically.???


prince_XY143
February 17th, 2010, 11:17 PM
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:

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

ddclondon
February 17th, 2010, 11:33 PM
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

prince_XY143
February 18th, 2010, 12:59 AM
[QUOTE=ddclondon;1918411][code]
THANKX ALOT................

HanneSThEGreaT
February 18th, 2010, 02:32 AM
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

ddclondon
February 18th, 2010, 03:12 AM
Your 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:


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.


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