Alex Rivera | Logout

How can I disable a tab inside a TabControl?

Asked 2009-01-06T20:30:44.247
103

Is there a way to disable a tab in a TabControl?

Edit
Report

2 Answers

89

The TabPage class hides the Enabled property. That was intentional as there is an awkward UI design problem with it. The basic issue is that disabling the page does not also disable the tab. And if try to work around that by disabling the tab with the Selecting event then it does not work when the TabControl has only one page.

If these usability problems do not concern you then keep in mind that the property still works, it is merely hidden from IntelliSense. If the FUD is uncomfortable then you can simply do this:

public static void EnableTab(TabPage page, bool enable) {
    foreach (Control ctl in page.Controls) ctl.Enabled = enable;
}
answered 2009-01-06T20:41:09.157
6

The only way is to catch the Selecting event and prevent a tab from being activated.

answered 2009-01-06T20:42:01.603

Your Answer