Controls in groupboxes

  • Thread starter Thread starter Steven Smith
  • Start date Start date
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...
 
* "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>
 
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
 
This more or less worked fine, cheers for the help cor,
got me out of a tricky spot
 
Back
Top