You can declare all the required controls as private members
when you need the control create an instance for it .write the code for its event handlers .Attach it to eventhandler when you want it
Main Topics
Browse All TopicsI'm developing an application in VB.NET on compact framework.
I'm creating a form with a variable number of controls, so i must create then at runtime. In vb6 i can create an array of controls and increment it. But not in vb.net.
so i need to create controls (textbox and combobox) giving then a name but how?
i can't declare something like << dim "textbox_12" as new textbox >> obviously
i tried
For i = 0 To 10
Dim newcontrol As New TextBox
newcontrol.Top = 20 * i
Me.Controls.Add(newcontrol
Next i
and it adds the controls to the form how can i manage then? How do i know what there is in textbox_12?
i could cycle in me.controls, but i can't identify the right control because "name" property is not supported in compact framework...
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Try this code
If you need the name property why are you inherit the control.
--------------------------
Imports System.IO
Public Class Form2
Inherits System.Windows.Forms.Form
Friend WithEvents Button1 As System.Windows.Forms.Butto
Dim TextBoxes(10) As MyTextBox 'Dont Create Instances
Dim i As Integer = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
End Sub
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Butto
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(200, 320)
Me.Button1.Size = New System.Drawing.Size(80, 24)
Me.Button1.Text = "Button1"
'
'Form2
'
Me.ClientSize = New System.Drawing.Size(282, 351)
Me.Controls.Add(Me.Button1
Me.Text = "Form1"
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBoxes(i) = New MyTextBox
TextBoxes(i).Location = New Point(10, 10 + i * 20)
TextBoxes(i).Size = New Size(100, 20)
TextBoxes(i).Name = "Text" & i
Me.Controls.Add(TextBoxes(
AddHandler TextBoxes(i).TextChanged, AddressOf TextBoxex_TextChanged
i += 1
End Sub
Private Sub TextBoxex_TextChanged(ByVa
Dim TempVar As MyTextBox
TempVar = DirectCast(sender, MyTextBox)
MsgBox(TempVar.Name)
End Sub
End Class
Public Class MyTextBox
Inherits TextBox
Private _Name As String
Public Sub New()
MyBase.New()
End Sub
Public Property Name() As String
Get
Return _Name
End Get
Set(ByVal Value As String)
_Name = Value
End Set
End Property
End Class
--------------------------
Business Accounts
Answer for Membership
by: Mikal613Posted on 2004-08-02 at 12:49:33ID: 11697380
I dont think you can but here is the hack for EVB maybe you can use that Idea.
/ zinc_eVB_ simulating _dynamic_c trls_pg1.a sp
http://devbuzz.com/content