Loop through controls

I

Inga2005

I have a winform with a number of user controls. On of the control is a
tab control which contains a number of pages where each page has
textboxes and other controls on it. I would like to loop through all
the texboxes on one of the tab pages and empty each and every one of
them. However, I only manage to loop through the separate tab pages and
not their content. Any ideas?
/erik
 
J

JezB

You need a recursive iteration. The form has a Controls collection, but
certain controls may also have their own Controls collection.
 
P

Pritcham

Hi

Something like the following should do:


Private Sub ClearControls(ByVal caller As Object, ByVal lock As
Boolean)
Dim ctl As Control
For Each ctl In caller.Controls
If ctl.HasChildren Then
ClearControls(ctl, lock)
End If
If TypeOf ctl Is Windows.Forms.TextBox Then
ctl.Text = String.Empty
End If
Next
End Sub

Hope that helps

Martin
 

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