How to set focus on control within tabcontrol when tab changes?

I have a tabcontrol with three tabs.

First tab has several controls.
Second tab has only one control.
And the last tab has several controls.

How do I set the focus to a control within a tab when the tab page changes?

Code such as the following did not work for me.

If Me.TabControl1.SelectedIndex = myTabPageTreatment Then
txbVisitTreatment.Focus()
End If

Thanks for all help!!!
vbn

Comments

  • i dont know if this is what u want..but ill try my luck nway.. :)
    basically..it's quite easy to set focus on any control...
    u just open up the properties window for that particular contol...look for an option of TabIndex..then change the tab index...
    set it to 0 for the control that u want to focus immediately as the tab loads and 1 for the next..2..3..and it goes on...
    go to the next tab and do the same thing for the controls on it...

    hope it helps..

    -raina-
  • Thanks Raina

    As it turns out I know about this and already have the tab sequence set as desired. I don't want to change the tab sequence (too many tabs with too many controls). I could not manually manage that. What I am looking for is: say you have a tab control with three tabs and each tab has 15 controls, plus labels , etc. When tab 1 is clicked, I want to be able to set the focus to a certain control within the tab. Ditto for tab 2 and tab 3.

    I appreciate your being gracious and taking the time to help. Many blessings to you.

    Thanks
    Vbn

  • Hello,
    You can do it like this.
    TablecontrolName.SelectTab(TabPageName)

    this way you can programmatically change the table
    E.g. you are clicking a button and changes the tab control.
    Hope this works, as for me , it did!

  • Suppose If you have One TabControl(Tabcontrol1) and three Tab pages
    (TabPage1,TabPage2,TabPage3).

    if you are in Tabpage1 and if you want to goto Tabpage3

    Code:
    ------

    TabControl1.SelectedTab = TabPage1

    txbVisitTreatment.Focus() ' If u want to focus to any control
  • Hi,
    The TabControl is a container control that allows you to display multiple tab on a single form and it allowed switching between the tabs....
    for more information check this link...
    [link=http://www.mindstick.com/Articles/0f9a1b51-f2e8-4343-ab35-4229f1f19b93/?TabControl in VB.Net]http://www.mindstick.com/Articles/0f9a1b51-f2e8-4343-ab35-4229f1f19b93/?TabControl in VB.Net[/link]

    thanks !!!
  • This post has been deleted.
  • This post has been deleted.
  • This post has been deleted.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories