Friday, May 6, 2011

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

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?

From stackoverflow
  • TabControl.SelectedIndex

    raven : Don't know how I missed that. Thanks.
  • WPF code, try this:

    if (tabControl1.SelectedValue == tabPage1)
        tabControl1.SelectedValue = tabPage2;
    else
        tabControl1.SelectedValue = tabPage1;
    
    peSHIr : WPF and the Compact framework don't mix, don't they...? (Or did I miss something?)
    peSHIr : Plus, this is exactly what the question says does not work: a working alternative was called for.
    Mark Kadlec : Sorry, I did miss the Compact statement but I believe SelectedValue will work in the compact framework, it is missing SelectedTab.

0 comments:

Post a Comment