I have TabControl
and 4 TabPages
. I need to select the second Tab programmatically!
Asked
Active
Viewed 4.4k times
10
-
2possible duplicate of [Activate tabpage of TabControl](http://stackoverflow.com/questions/3921224/activate-tabpage-of-tabcontrol) – Trevor Aug 13 '15 at 14:49
-
1If you did some searching there are many answers here on SO that clearly show how this is done. Here is one for example: **http://stackoverflow.com/questions/3921224/activate-tabpage-of-tabcontrol** (look @Gimly) answer. Also a quick Google search yielded me about 630,000 hits, just a suggestion. This isn't a programming problem, this is lack of doing research before asking a good question. – Trevor Aug 13 '15 at 14:50
2 Answers
28
You have two ways to do it
SelectedTab:
MyTabControl.SelectedTab = MyTabPage
(The TabPage you want to select)SelectedIndex:
MyTabControl.SelectedIndex = 1
(1 is the index of the second TabPage)

Matt Wilko
- 26,994
- 10
- 93
- 143

Amal
- 568
- 1
- 6
- 8
1
Here is my approach, I trust someone will find it helpful, using My.Settings:
Code for the exit button/routine:
Private Sub PicClose_App_Click(sender As Object, e As EventArgs) Handles PicClose_App.Click
' Save the current active tab index, this will be used on next startup to determine on which TabPage to start
My.Settings.Main_Form_Startup_TabPage = MyTabControl.SelectedTab.TabIndex
Application.Exit()
End Sub
Code called from the Load event of the main form:
Public Sub Form_Startup_TabPage()
' Get tab index from settings, 0 has been set as default
Dim IntStartup_TabPage As Integer = My.Settings.Main_Form_Startup_TabPage
' Select the last tab used
FrmMain.TabChar_Group_Selection.SelectedIndex = IntStartup_TabPage
End Sub

vicsar
- 301
- 5
- 16