0

Say I have a tab control with tabs Tab1 And Tab2. How do I switch the selected tab programmatically, say on button1 click event. Sample code would be appreciated.
Thanks in advance.

3
Contributors
2
Replies
17
Views
7 Years
Discussion Span
Last Post by Ketsuekiame
1

Hello jackabascal,

private void button1_Click(object sender, EventArgs e)
        {
            this.tabControl1.SelectedTab = this.tabControl1.TabPages["Tab2"];
        }

Should work
Cheers

1

The better way to do it is to use the "SelectTab" method

{
   /* Here I declared myTabControl and added three tabs named: "TabOne", "SecondTab", "EndTab"
      I also have an TabPage object bound to "SecondTab" called tabMySecondTab */
   myTabControl.SelectTab(0); // This selects "TabOne" as it is the first in the list
   myTabControl.SelectTab("EndTab"); // This selects the tab "EndTab"
   myTabControl.SelectTab(tabMySecondTab); // This selects the tab "SecondTab"
}

Edited by Ketsuekiame: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.