How do I programmatically select a tab on a .NET CF TabControl?
45,713
TabControl.SelectedIndex
Author by
user422801
Updated on July 30, 2022Comments
-
user422801 almost 2 years
With the .NET Framework 2.0/3.5 TabControl, I can programmatically select a tab using the SelectedTab property as shown in the code below:
//toggles between tabPage1 and tabPage2 private void button1_Click(object sender, EventArgs e) { if (tabControl1.SelectedTab == tabPage1) tabControl1.SelectedTab = tabPage2; else tabControl1.SelectedTab = tabPage1; }
The .NET Compact Framework TabControl doesn't have a SelectedTab property like its .NET Framework counterpart. So, how do I select a tab programmatically?
-
Lazy almost 15 yearsWPF and the Compact framework don't mix, don't they...? (Or did I miss something?)
-
Lazy almost 15 yearsPlus, this is exactly what the question says does not work: a working alternative was called for.
-
Mark Kadlec almost 15 yearsSorry, I did miss the Compact statement but I believe SelectedValue will work in the compact framework, it is missing SelectedTab.
-
Andrew Barber over 9 yearsThis question was not about .NET 4; it was about .NET CF.
-
Neil Dunlop about 7 yearsI found that when the TabControl is selected, it does not display correctly. It seems that after selecting a TabControl it is useful to Refresh it, so, where the TabControl is called TabForm and has mutliple Tabs, this might be: ` Me.TabForm.SelectedIndex = 0 Me.TabPg0.Refresh 'Where TabPg0 is the name of the Tab at Index 0`
-
Christian Larsson over 3 yearsWhat worked for me was to set "IsSelected" on the newest TabItem and then use UpdateLayout() on the TabControl:((TabItem)tabControl.Items[tabControl.Items.Count - 1]).IsSelected = true; tabControlCode.UpdateLayout();