Set focus on a tabpage

  • Thread starter Thread starter John Wright
  • Start date Start date
J

John Wright

I have the following routine I use to check for a certain tab page. I want to enable this tab page only on the tab control and set the focus. However, I cannot get the tab to set focus no matter what I do. Any suggestions?


Public Sub SetTabs(ByVal TabID As String)

For Each Ctrl As Control In Me.Controls

If TypeOf Ctrl Is TabControl Then

If Ctrl.HasChildren Then

For Each cCtrl As Control In Ctrl.Controls

If TypeOf cCtrl Is TabPage Then

If cCtrl.Name = TabID Then

Ctrl.Enabled = True

Ctrl.Visible = True

cCtrl.Enabled = True

cCtrl.Visible = True

Me.ActiveControl = cCtrl

Else

cCtrl.Enabled = False

End If

End If

Next

Else

Ctrl.Enabled = True

Ctrl.Visible = True

Me.ActiveControl = Ctrl

End If

End If

Next

End Sub
 
I have the following routine I use to check for a certain tab page. I want to enable this tab page only on the tab control and set the focus. However, I cannot get the tab to set focus no matter what I do. Any suggestions?

Public Sub SetTabs(ByVal TabID As String)

For Each Ctrl As Control In Me.Controls

If TypeOf Ctrl Is TabControl Then

If Ctrl.HasChildren Then

For Each cCtrl As Control In Ctrl.Controls

If TypeOf cCtrl Is TabPage Then

If cCtrl.Name = TabID Then

Ctrl.Enabled = True

Ctrl.Visible = True

cCtrl.Enabled = True

cCtrl.Visible = True

Me.ActiveControl = cCtrl

Else

cCtrl.Enabled = False

End If

End If

Next

Else

Ctrl.Enabled = True

Ctrl.Visible = True

Me.ActiveControl = Ctrl

End If

End If

Next

End Sub

You need to grab the tabpage object (or it's index) and then set
either the tabcontrol's selectedtab or selectedindex property to show
the tabpage.

Thanks,

Seth Rowe
 
Bingo. Thanks. I had to modify the code a little. I had to create a
tabcontrol object and set it = to the ctrl. Once this was done, I could set
the selectedtab to the tabpage I had. Thanks.

John
 
Back
Top