views:

199

answers:

3

I need to know how to make a tab item in a tab control unavailable for a certain kind of user.

The thing goes that after making 'log in', if the user is not the administrator, he will have one or two tabs unavailable. The admin will have access to the whole system.

I just want to make the tabs un-clickable. What are my options?

Thanks in advance

+3  A: 

In general:

System.Windows.Forms.TabPage.Enabled= false;

System.Windows.Forms.TabPage.Visible= false;

I prefer next approach:

tabAdmin.Visible = isAdmin;
abatishchev
awesome :D thanks!
Audel
@Audel: Glad it helped! :)
abatishchev
+2  A: 

you can try !

tab.TabPages.Remove(tabToRemove);

How to: Add and Remove Tabs with the Windows Forms TabControl

Or change the Enable and visible state of the tab.

if (!Admin)
{
   tab.Visible = false;
   tab.Enable = false;
}
anishmarokey
+1  A: 

EDIT:My answer is generic.

You better make them invisible than unclickable.
Regarding showing the tabs to user,Please check for the role the user is in. Here is my pseudocode..

if(User is Administrator)
{
//show the tabs
}
else
{
//dont show the tabs
}
Srinivas Reddy Thatiparthy