Activate tabpage of TabControl

C#WinformsTabcontrolTabpage

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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).

Solution 2 - C#

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);

Solution 3 - C#

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.

Solution 4 - C#

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

     mytabControl.SelectedIndex = 1

Solution 5 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionVyasdev MeledathView Question on Stackoverflow
Solution 1 - C#testalinoView Answer on Stackoverflow
Solution 2 - C#IvanView Answer on Stackoverflow
Solution 3 - C#GimlyView Answer on Stackoverflow
Solution 4 - C#Jerry AbrahamView Answer on Stackoverflow
Solution 5 - C#Wedson Quintanilha da SilvaView Answer on Stackoverflow