How do I programmatically select a tab on a .NET CF TabControl?

45,713

TabControl.SelectedIndex

Share:
45,713
user422801
Author by

user422801

Updated on July 30, 2022

Comments

  • user422801
    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
    Lazy almost 15 years
    WPF and the Compact framework don't mix, don't they...? (Or did I miss something?)
  • Lazy
    Lazy almost 15 years
    Plus, this is exactly what the question says does not work: a working alternative was called for.
  • Mark Kadlec
    Mark Kadlec almost 15 years
    Sorry, I did miss the Compact statement but I believe SelectedValue will work in the compact framework, it is missing SelectedTab.
  • Andrew Barber
    Andrew Barber over 9 years
    This question was not about .NET 4; it was about .NET CF.
  • Neil Dunlop
    Neil Dunlop about 7 years
    I 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
    Christian Larsson over 3 years
    What 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();