Set focus on a tabpage

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
 
R

rowe_newsgroups

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
 
J

John Wright

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top