By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,571 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,571 IT Pros & Developers. It's quick & easy.

Controls in groupboxes

P: n/a
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...
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
Nov 20 '05 #2

P: n/a
* "Steven Smith" <St**********@emailaccount.com> scripsit:
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>

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
This more or less worked fine, cheers for the help cor,
got me out of a tricky spot
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
.

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.