Rocshy
Rocshy

Reputation: 3509

c# move to next tab in a tab control

I have a TabControl, with 5 TabPages, is there any way I can go through every tab pragmatically? I want to be able to see on what tab the user is, and after he/she clicks a button, the next tab will become available, automatically, so they can write something in that page. Is this possible?

Upvotes: 2

Views: 18416

Answers (4)

wyomesh
wyomesh

Reputation: 11

myTabs.SelectedTab = myTabs.TabPages["yourTABName"]; will do that easily.

Upvotes: -1

BlueM
BlueM

Reputation: 6888

Choosing the next tab would be:

  tabControl.SelectedIndex = 
    (tabControl.SelectedIndex + 1) % tabControl.TabCount;

You can get the current Tab with

tabControl.SelectedTab

Upvotes: 0

George Johnston
George Johnston

Reputation: 32258

You can simply change the selected index:

tabControl1.SelectedIndex = (tabControl1.SelectedIndex + 1 < tabControl1.TabCount) ?
                             tabControl1.SelectedIndex + 1 : tabControl1.SelectedIndex;

In my example above, the SelectedIndex is increased based on the presently selected index -- if there is an additional tab to change to.

Upvotes: 5

alexsuslin
alexsuslin

Reputation: 4225

If we're speaking about WinForms TabControl, there is a property SelectedTab

Upvotes: 1

Related Questions