Best method to hide/show a single tabPage in a Tab control?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

This is probably an easy one, but I have not been able to figure it out so
far. I have a tab control on a windows forms app. Depending on some
business logic, I need to hide/show some of the individual tabs.

The tab page has no "visible" property. The tabpage class has a "hide"
method, but this does not seem to make it disappear. I have been able to
remove them via something like this:

this.tabControl1.Controls.Remove( myTab );

...but then I'm not sure how to put it back.
Can someone clue me in on how to hide & show tab pages dynamically?
I must be missing something obvious.

thanks
Robb
 
Hi Robb,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to hide a tabpage
and show it again. If there is any misunderstanding, please feel free to
let me know.

The tabpage has Visible property, but for some known issue it was not shown
in the intellisense. Calling the Hide method does the same thing as setting
Visible to false; However, on the tabpage control, the Hide method hides
all the controls in the tabpage but leave the tabpage itself visible. This
is the designed behavior as you can see in the following KB article.

http://support.microsoft.com/?id=834616

If you need to hide the tabpage, you have to remove it from the
tabControl.TabPages collection. And add it back if you need to show it
again. The TabPages collection doens't have an Insert method. The page will
be added to the last of the collection. In this case, I suggest you remove
all the tabpages and re-add them by order.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
I was all over the Internet yesterday looking for this, too. I found some
complicated workarounds but nothing easy in my app.

I finally bought the tab control from www.softelvdm.com and it works just
fine.

For the project I'm working on, it was just faster.
 
Robthis.tabControl1.Remove( myTab );
this.tabContro1.Add(myTab);

However better is to remove them all and to create all the tabs in the order
you want.
(You don't remove the actual tabpage only the reference from the tabControl)


(for the removing you can than use one method with a foreach)

I hope this helps,

Cor
 
Mick,

Sorry I forever forget that site from you and can than not find it anymore,
while I want to recoment it.

I was lazy this time and I thought that the problem was slightly different.

I have now set it in my HKW system.


:-)

Cor
 
That's OK Cor.
I don't expect other people to recommend my site, but it's nice when they
do.
 
Thanks everyone for the replies.

In the end I built a method which wraps the remove/add calls and does what I
want. The signature of the method is:

private void showTab ( Control tabPage, bool tabVisible )

This allowed me to encapsulte the annoying need to always either 1) check
for the existence of the tab in the controls collection before adding it, or
2) remove the tab before adding it, since it might already be there. Also
would serve as a good place to remove them all and re-add them, if I decided
to go that far. So far I haven't needed to worry about the ordering, but if
that becomes an issue I'll take your advice.

Thanks again for all the quick replies.

-Robb
 
Mick-

I did find your site, but the word Beta at the top scared me off. I needed
someone to yell at if the tab didn't work - we're on a pretty tight deadline.

John
 
John Davies said:
Mick-

I did find your site, but the word Beta at the top scared me off. I needed
someone to yell at if the tab didn't work - we're on a pretty tight
deadline.

John

I consider it Beta since I only test on WinXP. However, I have a lot of very
happy users and only occasionally do I get a report of some minor glitch
that is usually very easily rectified.

I don't think you'll find a better tabcontrol, but I may be slightly biased
;-)
 
Back
Top