By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 22 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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."

Nov 22 '05 #2

P: n/a
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.
Nov 22 '05 #3

P: n/a
Did you look here?
http://dotnetrix.co.uk/tabcontrols.html

My TabControlEX is free and would probably have done what you want.
http://dotnetrix.co.uk/controls.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"John Davies" <Jo********@discussions.microsoft.com> wrote in message
news:61**********************************@microsof t.com...
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.

Nov 22 '05 #4

P: n/a
Rob

this.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
Nov 22 '05 #5

P: n/a
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
Nov 22 '05 #6

P: n/a
That's OK Cor.
I don't expect other people to recommend my site, but it's nice when they
do.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
Nov 22 '05 #7

P: n/a
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
Nov 22 '05 #8

P: n/a
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
Nov 22 '05 #9

P: n/a
"John Davies" <Jo********@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
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
;-)

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
Nov 22 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.