87

I am using TabControl in a .NET application. By default, the first tab page of TabControl is showing in form loading. I want to show other tab pages in form loading. Programmatically, how can I show a different tab page?

domo
  • 27
  • 7
Vyasdev Meledath
  • 8,926
  • 20
  • 48
  • 68

5 Answers5

143
tabControl1.SelectedTab = MyTab;

or

tabControl1.SelectedTab = tabControl1.TabPages["tabName"];

Where tabName is the Name of the tab you want to activate (tabName is NOT the text display).

farid bekran
  • 2,684
  • 2
  • 16
  • 29
testalino
  • 5,474
  • 6
  • 36
  • 48
  • 12
    Alternatively, you may also use: **tabControl1.Select("NameOfTabToActivate");** –  Oct 13 '10 at 06:26
  • 2
    I have also used tabControl1.SelectedIndex = 0; – Owen Ivory Jun 02 '17 at 17:46
  • Why is this not a property on the Property window in the designer ? That does not makes any sense, one should be able to set this in the designer not only by code. – GuidoG May 24 '22 at 13:15
46

You can use the method SelectTab.

There are 3 versions:

public void SelectTab(int index);
public void SelectTab(string tabPageName);
public void SelectTab(TabPage tabPage);
The_Fox
  • 6,992
  • 2
  • 43
  • 69
Ivan
  • 461
  • 4
  • 2
20

There are two properties in a TabControl control that manages which tab page is selected.

SelectedIndex which offer the possibility to select it by index (an integer starting from 0 to the number of tabs you have minus one).

SelectedTab which offer the possibility to selected the tab object itself to select.

Setting either of these property will change the currently displayed tab.

Alternatively you can also use the Select method. It comes in three flavour, one where you pass the index of the tab, another the TabPage object itself and the last one a string representing the tab's name.

stuartd
  • 70,509
  • 14
  • 132
  • 163
Gimly
  • 5,975
  • 3
  • 40
  • 75
12

For Windows Smart device (compact frame work ) (MC75-Motorola devices)

     mytabControl.SelectedIndex = 1
Jerry Abraham
  • 1,039
  • 18
  • 42
9

Use SelectTab like this:

TabPage t = tabControl1.TabPages[2];
tabControl1.SelectTab(t); //go to tab

Use SelectedTab like this:

TabPage t = tabControl1.TabPages[2];
tabControl1.SelectedTab = t; //go to tab
Nick
  • 645
  • 5
  • 11