How to loop through groupbox controls?

E

Enric

Hi all of you,

Primary platform is .Net 2.0 using VB.

I'd need to clean every text property por each textbox allocated inside a
groupbox but I can't work out.
I enclosed to you my code snippet:

For Each ctrl As Control In Controls
If TypeOf ctrl Is GroupBox Then
??????????????
Else
End If
Next
Let me how do I such thing.

tia,
 
O

Onur Güzel

Hi all of you,

Primary platform is .Net 2.0 using VB.

I'd need to clean every text property por each textbox allocated inside a
groupbox but I can't work out.
I enclosed to you my code snippet:

For Each ctrl As Control In Controls
            If TypeOf ctrl Is GroupBox Then
??????????????
            Else
            End If
        Next
Let me how do I such thing.

tia,

Hi,
Try this to clear only textboxes inside a GroupBox:

' Assuming GroupBox1 is your GroupBox control
For x As Integer = 0 To GroupBox1.Controls.Count - 1
For Each ctrl As Control In GroupBox1.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Text = ""
End If
Next
Next

Hope this helps,

Onur Güzel
Next
 
A

Armin Zingler

Enric said:
Hi all of you,

Primary platform is .Net 2.0 using VB.

I'd need to clean every text property por each textbox allocated
inside a groupbox but I can't work out.
I enclosed to you my code snippet:

For Each ctrl As Control In Controls
If TypeOf ctrl Is GroupBox Then

for each innercontrol in ctrl.controls
if typeof innercontrol is textbox then
innercontrol.text = string.empty
end if
next innercontrol
Else
End If
Next
Let me how do I such thing.



Armin
 
C

Chris Dunaway

' Assuming GroupBox1 is your GroupBox control
For x As Integer = 0 To GroupBox1.Controls.Count - 1
For Each ctrl As Control In GroupBox1.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Text = ""
End If
Next
Next

That code will clear each TextBox more than once. Why do you have 2
for loops? All you need is the inner one.

Chris
 
O

Onur Güzel

That code will clear each TextBox more than once.  Why do you have 2
for loops?  All you need is the inner one.

Chris

Hi Chris,
You're right, in that case, that would be nicer:

' Assuming GroupBox1 is your GroupBox control
For Each ctrl As Control In GroupBox1.Controls
If TypeOf ctrl Is TextBox Then
ctrl.Text = ""
End If
Next


Onur Güzel
 

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