sa_leinad sa_leinad - 1 year ago 87
C# Question

Switching to a tab in TabControl using code

I have a tabcontrol in my application that has several tabs in it.

I want to automatically switch to another tab when the "Next" button is pressed.

I cannot figure out how to change which tab is visible programmatically.

private void Next_Click(object sender, EventArgs e)
// Change to the next tab

Answer Source

Use the TabControl.SelectedTab property. MSDN.

tabControl1.SelectedTab = anotherTab;

But you can also use the TabControl.SelectedIndex property. MSDN.

    tabControl1.SelectedIndex += 1;
    //This prevents the ArgumentOutOfRangeException.