To create dynamic text box or any other control. use the below code sample. Add a text box(To get the input for creating dynamic text box), a flowlayout to add the dynamic controls, a button to create dynamic controls.
'Declaration Dim Txtdynamic As TextBox Dim intcount As Integer Dim inttxtcnt As Integer
Add the below
Try
'to check the textbox for empty If Not TextBox1.Text Is String.Empty Then inttxtcnt = TextBox1.Text Else Exit Sub End If
'To create the dynamic text box and add the controls to Flowlayout panel For intcount = 0 To inttxtcnt - 1 Txtdynamic = New TextBox Txtdynamic.AutoSize = True
'set the font size Txtdynamic.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Txtdynamic.Name = "txtdynamic_" & intcount & "_mycntrl" FlowLayoutPanel1.Controls.Add(Txtdynamic) Next Catch ex As Exception MsgBox(ex.Message) End Try
'To get the values from dynamic created values
Dim intdyncnt As Integer 'to check the textbox for empty If Not TextBox1.Text Is String.Empty Then inttxtcnt = TextBox1.Text Else Exit Sub End If
Try
'To get the dynamic text box values which is added in flowlayout panel For intcount = 0 To inttxtcnt - 1 If Not TextBox1.Text Is String.Empty Then If FlowLayoutPanel1.Controls(intcount).Name = "txtdynamic_" & intcount & "_mycntrl" Then If CInt(Txtdynamic.Text) > 0 Then intdyncnt += CInt(FlowLayoutPanel1.Controls(intcount).Text) End If End If End If Next MsgBox(" The sum of the values is " & intdyncnt) Catch ex As Exception MsgBox(ex.Message) End Try
|
| Author: D.Jeya kumar(JK) 08 Aug 2008 | Member Level: Diamond Points : 0 |
hi,
good post keep doing it thanks
regards JK
|