Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Change SelectedTab when Child control gets focus

Change SelectedTab when Child control gets focus

Scheduled Pinned Locked Moved Visual Basic
csharp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gulfraz Khan
    wrote on last edited by
    #1

    I am using VB .NET 2005. I have a tab control in my form and the tab control contains 4 tab pages. Each tab page has different controls in it. If my selected (current) tab is 3rd tab and I set the focus to a child control in first tab page by using ControlName.Focus() The control does not fire any Enter/GotFocus event Is there anyway to set the SelectedTab or SelectedIndex of the TabControl to the TabPage in which the Control to be focused exists. Waiting for a quick reply. Thank You. -- modified at 12:14 Thursday 26th January, 2006

    J 1 Reply Last reply
    0
    • G Gulfraz Khan

      I am using VB .NET 2005. I have a tab control in my form and the tab control contains 4 tab pages. Each tab page has different controls in it. If my selected (current) tab is 3rd tab and I set the focus to a child control in first tab page by using ControlName.Focus() The control does not fire any Enter/GotFocus event Is there anyway to set the SelectedTab or SelectedIndex of the TabControl to the TabPage in which the Control to be focused exists. Waiting for a quick reply. Thank You. -- modified at 12:14 Thursday 26th January, 2006

      J Offline
      J Offline
      Joshua Quick
      wrote on last edited by
      #2

      Here's a few quick tips... You can change the tab selection like this. myTabControl.SelectedTab = myTabPage You can find out which TabPage a control belong's to by searching the TabPage.Controls collection. Also, the control's Parent property "might" return a reference to the TabPage that owns it. You'll have to test that one out to be sure.

      G 1 Reply Last reply
      0
      • J Joshua Quick

        Here's a few quick tips... You can change the tab selection like this. myTabControl.SelectedTab = myTabPage You can find out which TabPage a control belong's to by searching the TabPage.Controls collection. Also, the control's Parent property "might" return a reference to the TabPage that owns it. You'll have to test that one out to be sure.

        G Offline
        G Offline
        Gulfraz Khan
        wrote on last edited by
        #3

        Thank you for your reply. I have tried by setting the tag property of each control on the tab page to the index of its tab page (i.e. 0 for controls on first tab, 1 for second etc.) at design time. Then I have dynamically associated the event handler for "Enter" event of each control on the tab page. Event handler looks like TabControl1.SelectedIndex = DirectCast(sender, Control).Tag But the control does not get focus when I call the .Focus() method I don't want to explicitly call the TabControl1.SelectedIndex before setting Focus to any control. Is there anyway?

        J 1 Reply Last reply
        0
        • G Gulfraz Khan

          Thank you for your reply. I have tried by setting the tag property of each control on the tab page to the index of its tab page (i.e. 0 for controls on first tab, 1 for second etc.) at design time. Then I have dynamically associated the event handler for "Enter" event of each control on the tab page. Event handler looks like TabControl1.SelectedIndex = DirectCast(sender, Control).Tag But the control does not get focus when I call the .Focus() method I don't want to explicitly call the TabControl1.SelectedIndex before setting Focus to any control. Is there anyway?

          J Offline
          J Offline
          Joshua Quick
          wrote on last edited by
          #4

          Calling Focus() won't change the tab selection. Plus a control won't gain Focus if it's not visible. You're going to have to show the tab page yourself. Now, if you want to keep it generic, I suppose you can do something like this. Just pass the control you want to give focus to in this function. It's just that easy.

          Private Sub SetControlFocus(ByVal ctrl As Control)
          ' Validate argument.
          If (ctrl Is Nothing) Then Return

          ' If control belongs to a tab page, then show it.
          If (TypeOf ctrl.Parent Is TabPage) Then
          myTabControl.SelectedTab = DirectCast(ctrl.Parent, TabPage)
          End If

          ' Give control focus.
          ctrl.Focus()
          End Sub

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups