how can i disable one or more tab pages on a tabControl ?
Hi there, i would like to know how can i disable one or more tab pages on a tabControl (Visual C#.net 2005)? thanks in advance for your time and for sharing your knowledge. Cheers from Bolivia.
Kirtan PatelPosted Nov 18, 2008, 4:34 PM
so u have to make it unselected when user try to select it
here is code i have written to prevent access to tab
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
//To Disable Tab 4
if (tabControl1.SelectedTab == tabPage4)
{
tabControl1.SelectedTab = tabPage1;
}
}
There is no other Way to disable tab else this its defined in MSDN
Happy Coding :)
JamesPosted Nov 30, 2008, 3:56 AM
First, create a variable such as: System::Windows::Forms::TabPage^ selectedTab
(load in the default tab into the selectedTab variable upon instantiation of the class)
Set the enabled property of the tabs then create a index changed event like so:
private: System::Void tabControl1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
if(tabControl1->SelectedTab->Enabled == false)
{
tabControl1->SelectedTab = selectedTab;
}
else
{
selectedTab = tabControl1->SelectedTab;
}
}
Not a very profound Idea, but it works.
JamesPosted Nov 30, 2008, 3:24 AM
Satish KathiPosted Nov 18, 2008, 5:16 PM
There is an Enable property for a Tab Page
You cannot see it because its Browsable attribute is set to false and EditorBrowsable is set to EditorBrowsableState.Never
You can set Enable property of a TabPage to true/false
The code which I described above works fine
Satish KathiPosted Nov 18, 2008, 3:57 PM
//Enabled is the property used to set enable status of the tab page
//If you want user should not able to select the disabled tab page
//then handle the tabcontrol selecting event
//here is a sample example
//Check box enables or disables a tab page
private void chkEnableTabpage2_CheckedChanged(object sender, EventArgs e)
{
if(chkEnableTabpage2.Checked)
tabPage2.Enabled = true;
else
tabPage2.Enabled = false;
}
//When user is selecting the disabled tab page cancel the selection
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
{
if (!e.TabPage.Enabled)
{
e.Cancel = true;
}
}
azariel moronPosted Nov 18, 2008, 10:48 AM
Bechir BejaouiPosted Oct 31, 2008, 7:03 PM