Medic3000
Medic3000

Reputation: 786

how to make a tabpage inaccessible in tabcontrol

I currently have a tabcontrol with 3 tabpages (lets call them A,B, and C) the thing is I want the user to only be able to click certian tabs (if on tabA only can navigate to tabB, if on tabC only can navigate to tabA...) is there a way to do this? I'm a bit stumped, any help is appreciated thanks!

--C#2.0
--Windows Visual Studio 2005

Upvotes: 0

Views: 682

Answers (4)

DROP TABLE users
DROP TABLE users

Reputation: 1955

Maybe something like

If (SelectedIndex == 1) //tab a
{
    tabC.enabled = false;
    tabB.enabled = true;
}

Upvotes: 1

Thelonias
Thelonias

Reputation: 2935

You could hook up to the Selecting event on the TabControl and inside the event handler, you could check some class variable specifying which tab(s) are allowed to be clicked. If the one you're selecting doesn't match the variable, you can cancel the event.

Upvotes: 1

Jake
Jake

Reputation: 11430

Add a handler to the TabControl.Selecting event to check whether you want to allow the tabpage selection.

Upvotes: 1

JeffS
JeffS

Reputation: 428

In order to control which TabPages you can navigate to at a time, you can use the Enabled property on the TabPage. Set it to false in order to prevent any user from being able to interact with it.

In order to dynamically decide which tabs are enabled based on what tab is open you can use the Selected event on the TabControl (detailed here: http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol.selected.aspx). This will fire whenever you change the current tab on the TabControl. In here, you can determine what the current TabPage is and then use that to enable or disable TabPages as appropriate.

Upvotes: 1

Related Questions