TabControl.SelectedIndex Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets the index of the currently selected tab page.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public int SelectedIndex { get; set; }

Property Value

Type: System.Int32

The zero-based index of the currently selected tab page. The default is -1, which is also the value if no tab page is selected.

Exception Condition

The value is less than -1.

The following code example creates a TabControl with two TabPage objects. The SelectedIndex property sets tabPage2 as the currently selected tab page using its index value.

Use the System.Drawing and System.Windows.Forms namespaces for this example.

using System.Drawing;
using System.Windows.Forms;

public class Form1 : Form
    private TabControl tabControl1;
    private TabPage tabPage1;
    private TabPage tabPage2;

    private void MyTabs()
        this.tabControl1 = new TabControl();
        this.tabPage1 = new TabPage();
        this.tabPage2 = new TabPage();

        this.tabControl1.Controls.AddRange(new Control[] {
        this.tabControl1.Padding = new Point(15, 10);
        this.tabControl1.Location = new Point(35, 25);
        this.tabControl1.Size = new Size(220, 220);

        // Selects tabPage2 using SelectedIndex.
        this.tabControl1.SelectedIndex = 1;

        this.tabPage1.Text = "myTabPage1";
        this.tabPage1.TabIndex = 0;

        this.tabPage2.Text = "myTabPage2";
        this.tabPage2.TabIndex = 1;

        this.Size = new Size(300, 300);
        this.Controls.AddRange(new Control[] {

    public Form1()

    static void Main() 
        Application.Run(new Form1());

.NET Framework
Available since 1.1
Return to top