Accessing all controls on a tabcontrol??

P

Paul Bromley

I am using a tabcontrol alled for example:-

TabPage

There are several tabs on this tabcontrol with command buttons on them. I
want to loop through them but the following code does not work:-

For Each ctl in TabPage.Controls ... Next

However if I just loop through controls on one of the tabs - e.g. a tab
called tabFirst this works fine:-

For Each ctl in tabFirst.Controls ... Next

How do I get the Controls on all of the tabs??


Thanks

Paul Bromley
 
H

Herfried K. Wagner [MVP]

Paul,

Paul Bromley said:
There are several tabs on this tabcontrol with command buttons on them. I
want to loop through them but the following code does not work:-

For Each ctl in TabPage.Controls ... Next

However if I just loop through controls on one of the tabs - e.g. a tab
called tabFirst this works fine:-

For Each ctl in tabFirst.Controls ... Next

How do I get the Controls on all of the tabs??

\\\
For Each tab As TabPage In Me.TabControl1.TabPages
For Each ctr As Control In tab.Controls
...
Next ctr
Next tab
///

Note that this won't find controls which are nested in container controls
placed on the tab pages.

BTW: I would not use the name 'TabPage' for a tab control because the tab
pages are instances of the class 'TabPage', which could be misleading for
the reader.
 
P

Paul Bromley

Thanks Herfried,
I suspected that I needed to loop through through the tabpages. I had
foolishly placed:-

For Each ctr As Control In Controls

In my code instead of:-

For Each ctr As Control In tab.Controls
Thanks once again.


Paul Bromley

T
 

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