467,923 Members | 1,271 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

Accessing dynamically created controls

Hi all,
I am trying to create a VB smart device application.
I create few buttons dynamically on form_load...

something like this:
Dim WithEvents BtnOperate As New OpenNETCF.Windows.Forms.Button2
Me.BtnOperate.Location = New System.Drawing.Point(20, 20)
Me.BtnOperate.Size = New System.Drawing.Size(150, 150)
Me.BtnOperate.TabIndex = 0
Me.Controls.Add(Me.BtnOperate)
Me.BtnOperate.BackgroundImage = b

then i have a datareceived event in a module, where i receive a command to set focus on one of the buttons (for example left of the one that currently has a button), i tried this trough the property
like this:
Public Property CtrlFocus() As Integer
Get
Dim i As Integer = Me.Controls.Count
Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.Focused Then
Return ctrl.TabIndex
End If
Next
End Get
Set(ByVal value As Integer)
Dim ctrl As Control
For Each ctrl In Me.Controls
If ctrl.TabIndex = value Then
ctrl.Focus()
End If
Next
End Set
End Property

with this commands that are in my module...:
dim fm as new frm_main
index = fm.CtrlFocus
frm_main.ctrlfocus = index +1

but when i try this there is no controls in me.controls in property CtrlFocus!
How could I access dynamically created controls from another thread...or get a list of them...

Hope this is clear whats the problem.
Thanks
Grega
May 8 '07 #1
  • viewed: 1572
Share:
1 Reply
i think you can solve prob



i have used the follwing code in page load event to dynamically generate 5 text boxs.

Dim i As Integer
For i = 1 To 5
Dim txtBox As New TextBox
txtBox.ID = String.Format("txtBox{0}", i)
Panel1.Controls.Add(txtBox)
Next

now i want to display those entered text in same page when i click on button..
so please help me out... its urgent
May 8 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Jonathan Williams | last post: by
1 post views Thread by drakuu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.