Question about Control Collection in VB.net

  • Thread starter Thread starter matthew ware
  • Start date Start date
M

matthew ware

Hi.

I've got a form and I want to iterate through the controls on it. I've
tried:

For intCounter = 0 to Me.Controls.Count -1
' do something
next intCounter

But the Me.Controls.Count only evaluates to 5, even though there are alot
more controls on the form.

Any Ideas?

thanks,

Matt
 
Hi Matt,

Do the missing controls belong to the form or to other container control
(GroupBox, TabControl)? In the latter case, you need to use recursion to get
them.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com
 
matthew ware said:
I've got a form and I want to iterate through the controls on it. I've
tried:

For intCounter = 0 to Me.Controls.Count -1
' do something
next intCounter

But the Me.Controls.Count only evaluates to 5, even though there are alot
more controls on the form.

\\\
Private Sub RecurseControls(ByVal ctr As Control)
Debug.WriteLine(ctr.Name)
If ctr.HasChildren Then
For Each c As Control In ctr.Controls
RecurseControls(c)
Next c
End If
End Sub
..
..
..
RecurseControls(Me)
///
 
Hi Carlos.

Brilliant! Yes, the missing controls were on a tab control - now fixed.

thankyou,

Matt.
 

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

Back
Top