How can I get child control in GroupBox ??

L

Lin Yi-Jian

Dear All:

I have a GroupBox1 in my form, and I add a TextBox1 to GroupBox1.

I want to set some string to TextBox1,how can I do ??

my program:
Dim tt as TextBox
tt=me.controls.item("TextBox1") <--------- Cannot get this
object,it only can get GroupBox1
tt.text="Hello"
 
G

Guest

I assume you are adding the textbox dynamically (in code) rather than in the
designer. [If the textbox is added in the designer, you would access the
textbox directly: Me.Textbox1]

For a set of controls added dynamically to a container control, such as the
GroupBox...you could do this...

Dim G As New GroupBox()
Dim t As New TextBox()
Dim tt As TextBox
t.Name = "t"
G.Controls.Add(t)
(add code to for size and location)
Dim i
For i = 0 To G.Controls.Count - 1
If G.Controls(i).Name = "t" Then
tt = DirectCast(G.Controls(i), TextBox)
End If
Next
 
R

rowe_newsgroups

I assume you are adding the textbox dynamically (in code) rather than in the
designer. [If the textbox is added in the designer, you would access the
textbox directly: Me.Textbox1]

For a set of controls added dynamically to a container control, such as the
GroupBox...you could do this...

Dim G As New GroupBox()
Dim t As New TextBox()
Dim tt As TextBox
t.Name = "t"
G.Controls.Add(t)
(add code to for size and location)
Dim i
For i = 0 To G.Controls.Count - 1
If G.Controls(i).Name = "t" Then
tt = DirectCast(G.Controls(i), TextBox)
End If
Next

Also if using VS2005 you have access to the FindControl method you can
use to find child controls.

Thanks,

Seth Rowe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top