How to Disable a tabpage in a tabcontrol?

i need to disable a tabpage in a tabcontrol. Is there any good solution to this the tabcontrol doesnt have a selecting event. Please help.


Answer this question

How to Disable a tabpage in a tabcontrol?

  • Pankaj Sharma

    Disabling and hiding tabs is a common issue.

    The link is to a thread which discussed and has code as well.

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=400894&SiteID=1

    Hope that helps.


  • Maarten ter Mors

    The TabControl does have a selecting event in VS2005, but pre VS2005 it does not.

    The standard MS TabControl does not allow disabling of tabs. MS state that tabs that can not have any user interaction should not be shown, and so the associated tabpages should be removed.

    You will find routines on my site to remove and replace tabpages aswell as code to give you a selectedindexchanging event.

    http://www.dotnetrix.co.uk/tabcontrols.html

    You will also find TabControlEX (a free control) which allows you to disable tabs rather than remove them. It also has a SelectedIndexChanging event.

    http://www.dotnetrix.co.uk/controls.html


  • LeeH1972

    In which case you will need to ownerdraw the tabcontrol to get the appearance. Then add the code from my site (link in my previous post) which gives you a SelectedIndexChanging event and in that event set e.Cancel to true if e.NextTab is disabled.

    Alternatively, if you still want Visual Styles and don't want the hassle of ownerdrawing the tabs, just use TabControlEX (link in my previous post).


  • Daniel Hilgarth

    I dont want the hide and show technique. I still preffered the disabled tabpage. I want a tabpage which is gray and unclickable. For me that is the ideal way of disabling a tabpage.


  • HibaAli

    Hi,

    Try to hide it, if you can't disable it, it's so simple!!


  • Taurkon

    How about adding this to the tabcontrol SelectedIndexChanged event

    ' assuming that the index of the disabled tab is 2

    if tabcontrol1.selectedIndex=2 then

    msgbox("This tab has been disabled!")

    tabcontrol1.selectedIndex=1

    end if

    "There's probably a better way - but it works" - that's my new motto

    Mark


  • Dennis de Jong

    When i set the tabcontrol ownerdraw it doesnt look similar to the other tabcontrols.


  • mkpark

    If hiding it doesn't work (i can't seem to hide mine either) do a search on the msdn forums for removing a tabpage

    there is some code somewhere that you can use to remove a tabpage, save it and then display it again later, using tab.remove/tab.add

    I think it was originally in C# code, but someone im sure can convert it. I did have the link but i can't find it now :)


  • How to Disable a tabpage in a tabcontrol?