TabControl - Disable/Enable tab page

I have a tabcontrol with 2 pages. OnLoad the 2nd Tabpage shall be disabled (grayed out and not selectable). Later with code I need to enable the 2nd tab. Any Ideas how this can be done please.

/Morten


Answer this question

TabControl - Disable/Enable tab page

  • DoronM

    I entered the statement me.Me.TabPage5.Enabled = False.  It compiled OK, but didn't stop me from clicking it open.

    I also tried in form load the following two statements.

    Me.TabPage5.CanSelect = False
    complains CanSelect is ReadOnly

    OK, it is readonly in runtime, but why can't I set it someplace in design time.

    Me.TabPage5.Hide = True
    Complains Me.TabPage5.Hide is a Value therefore cannot be target of an assignment

    If me.TabPage5.Hide is a value, why isn't me.TabPage5.Enabled, CanSelect or any other property not a value.

    The selecting documentation is vacuous, and doesn't exist in vs studio 2003.  Furthermore, the selectedindexchanged documentation in both the vs 2005 and vs 2003 is of little help. 

    I have no clue how to stop a tab from being clicked or hiding it. This is a real shortcoming in the control and the documentation.

    dennist


  • HappyNomad

    David,

    I apologize.

    But I will buy a third party subscription.

    dennist685


  • DaTimelord

    I think the gymnastics I'd have to go through to 'mimic' disabling a tab page are ridiculous.

    All third party tab controls make this as easy as in vb6.  Obviously there's widespread desire for the ability.

    Microsoft's attitude is elitist.  You snobs may not see a need for it, but we lowly everyday programmers and our clients need them.

    Now I'm forced to put out good money for third party controls.  I've have to buy a subscription so I can update them as vs studio or the net framework is updated.

    It's similar with asp.net 2.0.  It's a hassle with styles and formatting to get detailsview or any other databound server control to have a sharp look to them. Why aren't they as sharp as winform controls, without any contortions   Third party asp.net controls are sharp without configuring styles and formatting.  You snobs are forcing us to put out an extra $1,000 a year for r.a.d, componentone, or infragistics.

    Given the big bucks we already have to pay for production versions of vs studio 2005, I think you're ripping us off.

    dennist685


  • BetaStar

    Thank you Mick,

    But I'll still buy a subscription, if only for the asp.net controls, that look like real controls without having to mess with styles and formatting.

    dennist685


  • Mr. Trevisan Andrea

    Maybe you could remove the tab altogether from the TabControl and add it later when it's needed.

    Just an idea.

    Luis Alonso Ramos


  • rennard

    No we are not making things complicated. Hide and unhide is not an option, the users should be able to see the disabled tabs for navigation purposes.

    Microsoft is claiming that this control is working as designed and if you dive a little more down to their arguments see bugs/features they can simply not understand the use for this enable/disable tabs on a tab control and they are not encouraging any communication about this in order to better understand their customers.

    Several have asked for this feature all the way back from when MS first introduced the tab control. And if you are developing real live applications and using the tab control for more than configuration panels you will need this feature to disable and enable one or more tabs on a tab control.

    Right now the only alternative to this is buying a whole control package from a third party vendor, however I feel stupid when doing so just for this single feature/control.

    /Morten
     

  • givemejava

    No need to buy anything. TabControlEX supports this feature and it's free.

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

     


  • anand_CE

    I need this functionality as well and it was never confusing to my clients under VB6 and they worked fine there.  The properties "enabled" and "visible" were always available under VS 2002/2003 and just never seemed to work.  If this is by design, then why do the properties "enabled" and "visible" still exist and help pages show how to use them (see any of the object references and there is MS-sponsored code showing how to "disable a tab page in code").  Both of these MS references supposedly show you how to do this in code:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/vbcon/html/vbtskchangingappearanceofwindowsformstabcontrol.asp
    and
    http://msdn.microsoft.com/library/default.asp url=/library/en-us/vbcon/html/vbtskdisablingtabpagesprogrammatically.asp

    Come on MS, either remove all references to these properties or implement them.  The only thing confusing with this issue is MS inconsistency in implementing the properties and the continued help references to them.


  • Vampier

    David, you said,

    Disabling a tab page is not intuitive. If I saw a disabled tab page (besides swearing at the designer of the dialog), I would wonder 1. why it was disabled, and 2. how could I get it enabled. Disabling a tab page is a sign of bad user interface design.

    My users never were confused.  And all the users of the third party tab controls, including asp.net 2.0 tab controls think their users won't be confused.

    I give visual clues, or simply tell the user when to click the next tab control in a label.

    Nobody has ever complained or been confused.  Obviously the millions of users of vb6 applications weren't confused either.

    It's still a rip-off. It's too late in my career to switch to Java.  I don't like the language anyway.  I love visual basic.  I like programming but love my applications, which is I am a visual basic programmer.

    You snobs are interested in some abstract purity. But I'm a down to earth engineer. Visual basic was designed for people like me. We know much better than you what makes average users confused, and know what visual clues they need to avoid confusion.

    I produce small scale applications and actually speak to many of the people who use them, even those who use them on the web.

     

    dennist685

    dennist685

    dennist685


  • Angela Alviento

    > You snobs are interested in some abstract purity. But I'm a down to earth engineer. Visual basic was designed for people like me. We know much better than you what makes average users confused, and know what visual clues they need to avoid confusion.

    You have made the assumption that you know better than us 'snobs', yet you have no idea of my background. I doubt you spend the millions of dollars a year Microsoft does on usability tests (yes with 'real' users) that test this kind of thing but then again that would be an assumption - maybe you do.

    Anyway this topic is getting way off track. I provided a solution above, so I don't actually what the problem is unless you need to be converted to Visual Basic.



  • tgerbert

    You can't disable a tab as such, but you could mimic it.

    You could do something like the following:

    1. Add a TabControl with 2 pages
    2. Set DrawMode to OwnerDrawFixed
    3. Attach the TabControl.Selecting event to tabControl1_Selecting
    4. Attach the TabControl.DrawItem event to tabControl1_DrawItem
    5. Then copy the following code into your form (you will have to change it a little)


      public Form1()
      {
       InitializeComponent();

       tabPage2.Enabled = false;

      }
      private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
      {
       if (!e.TabPage.Enabled)
       {
        e.Cancel = true;
       }
      }

      private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
      {
       TabPage page = tabControl1.TabPages[e.Index];

       if (!page.Enabled)
       {
        using (SolidBrush brush = new SolidBrush(SystemColors.GrayText))
        {
         e.Graphics.DrawString(page.Text, page.Font, brush, e.Bounds);
        }
       }
       else
       {
        using (SolidBrush brush = new SolidBrush(page.ForeColor))
        {
         e.Graphics.DrawString(page.Text, page.Font, brush, e.Bounds);
        }
       }
      }


     



    Basically what you are doing is drawing your own tabs. You are disabling the TabPage in your constructor - be aware that the TabPage.Enabled is not visible in the designer or intellisense - but it does exist.

    Then in the selecting event you are stopping the focus from changing to a disabled page. In the DrawItem you are drawing the tabs yourself, so that you can mimic the disabled tab.

    This is not a complete solution, but it will get you started.

    HTH

    David



  • Kapalic

    It's not a shortcoming of the control as its actually by design. A disabled tab page can be confusing to a user.

    Anyway, did you actually try using the code I post above

    Setting TabPage5.Enabled = false, is not enough, you also need to do the things that I posted above.

  • Jaimz

    Why would Microsoft allow a feature (such as disabling a TabControl) that goes against their own user interface design guidelines

    Disabling a tab page is not intuitive. If I saw a disabled tab page (besides swearing at the designer of the dialog), I would wonder 1. why it was disabled, and 2. how could I get it enabled. Disabling a tab page is a sign of bad user interface design.

    The reason these properties exist is because they inherit them from Control. In both .NET 1.1 and .NET 2.0 these properties are hidden in the designer.



  • EBM

    You guys are making things complicate.
    Just call the tab page's parent control and ask it remove the tab page when you want to hide it and add it when you show it again.

  • TabControl - Disable/Enable tab page