Reputation: 596
I would like to disable tab selection when clicking on a button. For this I am using the following code:
foreach (TabPage page in scenarioSelectionTab.TabPages)
{
if (scenarioSelectionTab.SelectedTab != page) page.Enabled = false;
}
The problem is, when I use the code above, this disables the current tab as well. How can I prevent it?
Upvotes: 0
Views: 186
Reputation: 5217
Try this variant:
foreach (TabPage page in scenarioSelectionTab.TabPages) {
((Control)page).Enabled = scenarioSelectionTab.SelectedTab == page;
}
TabPage class DON'T have working Enabled property. Read MSDN.
If this don't work, try another variant with selected event:
private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) {
if (e.TabPage != scenarioSelectionTab.SelectedTab) e.Cancel = true;
}
Upvotes: 1
Reputation: 236188
You are only disabling pages - that's why when you can't enable another tab. Just set Enabled
state for each tab page:
foreach (TabPage page in scenarioSelectionTab.TabPages)
{
page.Enabled = scenarioSelectionTab.SelectedTab == page;
}
Upvotes: 1