Controls in groupboxes

S

Steven Smith

Hi guys I'm using object variables to address several
controls on a form like so...

Private Sub cmdReset_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) _
Handles cmdReset.Click

Dim intX As Integer
Dim objTextBox As TextBox
For intX = 0 To Controls.Count - 1
If TypeOf Controls.Item(intX) Is TextBox Then

objTextBox = Controls.Item(intX)
objTextBox.Text = ""
End If
Next intX

This works fine for any textboxes on my form outside of
groupboxes, The problem is I must also address the
textboxes within the groupboxes.

How do I reference these controls, surely it must be
possible to access controls within groupboxes I'm sure
I'm missing something simple.

Can anyone point me in the right direction... ?

Thanks in advance
Regards Steve...
 
H

Herfried K. Wagner [MVP]

* "Steven Smith said:
Hi guys I'm using object variables to address several
controls on a form like so...

Private Sub cmdReset_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) _
Handles cmdReset.Click

Dim intX As Integer
Dim objTextBox As TextBox
For intX = 0 To Controls.Count - 1
If TypeOf Controls.Item(intX) Is TextBox Then

objTextBox = Controls.Item(intX)
objTextBox.Text = ""
End If
Next intX

This works fine for any textboxes on my form outside of
groupboxes, The problem is I must also address the
textboxes within the groupboxes.

How do I reference these controls, surely it must be
possible to access controls within groupboxes I'm sure
I'm missing something simple.

<http://www.mvps.org/dotnet/dotnet/samples/controls/downloads/EnumerateControls.zip>
 
C

Cor

Hi Steven,
I did not check if the methode you use works, it is unusual but why not.
Private Sub cmdReset_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) _
Handles cmdReset.Click
Dim intX As Integer
Dim objTextBox As TextBox
For intX = 0 To Controls.Count - 1

I think here it has to be
For intX = 0 to Groupbox.Controls.Count - 1
If TypeOf Controls.Item(intX) Is TextBox Then

objTextBox = Controls.Item(intX)
objTextBox=Groupbox.Item(intX)

objTextBox.Text = ""
End If
Next intX
Do I don't know if it works but I think so.

Normal is typed, maybe type errors
\\\
dim ctrl as control
For each ctrl in groupbox.controls
if typeof ctrl is textbox then
ctrtxt = directcast(ctrl, textbox)
ctrtext=""
end if
next
///
Cor







Cor
 
S

Steven Smith

This more or less worked fine, cheers for the help cor,
got me out of a tricky spot
 

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