954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Dynamics text Box At run time

Hi Guys,
I need some urgent help..
My requirement is to create dynamic text boxes during run time.
it shld b like this: when i click a button a text box shld b created and upon entering a value it shld be saved in access database.
appreciare ur help and quick responce.

regards,
vammy

vammy
Light Poster
44 posts since Nov 2011
Reputation Points: 8
Solved Threads: 0
 

The noob way is to create the textbox, with visible=False and change visibility on button click.
If that won't do for you, read here : http://www.daniweb.com/software-development/vbnet/threads/318076
or here:
http://www.daniweb.com/software-development/vbnet/threads/101111

adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 

See if this helps to create Dynamic.TextBoxes on a Form.

Public Class Form1
#Region "----===----===----===----- myCoolDYNAMICS  -----===----===----===----"
    Private Sub createCoolTextBoxes()
        '// # at end of TextBox, location from Left to Right, location from Top to Bottom.
        Dim iCoolNumberForName As Integer = 1, iLeftLocation As Integer = 5, iTopLocation As Integer = 5
        '// create Dynamic.TextBox.
        Dim txt As New TextBox With {.Name = "TextBox" & iCoolNumberForName.ToString, .Left = iLeftLocation, .Top = iTopLocation, .Text = .Name}
        Me.Controls.Add(txt) '// add txtBox to Form.
        iCoolNumberForName += 1 : iLeftLocation += 5 : iTopLocation += 25
        txt = New TextBox With {.Name = "TextBox" & iCoolNumberForName.ToString, .Left = iLeftLocation, .Top = iTopLocation, .Text = .Name}
        Me.Controls.Add(txt) '// add txtBox to Form.
        iCoolNumberForName += 1 : iLeftLocation += 5 : iTopLocation += 25
        txt = New TextBox With {.Name = "TextBox" & iCoolNumberForName.ToString, .Left = iLeftLocation, .Top = iTopLocation, .Text = .Name}
        Me.Controls.Add(txt) '// add txtBox to Form.
        '// etc./etc.
    End Sub
#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        createCoolTextBoxes()
    End Sub
End Class

As for getting values from your new TextBoxes, check out this recent post of mine . The second part of code, w/the sTemp &= CType(Me.Controls(<strong>"TextBox" & i</strong>.ToString), TextBox).Text ; i being iCoolNumberForName in the above code.

codeorder
Posting Virtuoso
1,915 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
 

Hi Adam,
Thnks for the solution.It worked for me.
and also thnks you codeorder for ur intervention here,.thanks alot guys,

vammy
Light Poster
44 posts since Nov 2011
Reputation Points: 8
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: