Home All Groups Group Topic Archive Search About

Question about Control Collection in VB.net

Author
3 Feb 2006 11:11 AM
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

Author
3 Feb 2006 11:15 AM
Carlos J. Quintero [VB MVP]
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


Show quoteHide quote
"matthew ware" <mattheww***@email.com> escribió en el mensaje
news:%23pn8JKLKGHA.648@TK2MSFTNGP14.phx.gbl...
> 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
>
Author
3 Feb 2006 12:19 PM
matthew ware
Hi Carlos.

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

thankyou,

Matt.


Show quoteHide quote
"Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in message
news:eHt4sMLKGHA.4068@TK2MSFTNGP10.phx.gbl...
> 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" <mattheww***@email.com> escribió en el mensaje
> news:%23pn8JKLKGHA.648@TK2MSFTNGP14.phx.gbl...
>> 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
>>
>
>
Author
3 Feb 2006 11:24 AM
Herfried K. Wagner [MVP]
"matthew ware" <mattheww***@email.com> schrieb:
> 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)
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>