Results 1 to 15 of 15

Thread: Select Tab

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Select Tab

    Hi,

    I'm trying to make a tab page change on SelectedIndexChanged event of a combo box.
    I have used select case statements to try and do it, but can't get the tab to change.

    I have tried tabpage.select , tabpage.focus , and few others, but none of them seem to work.

    I don't get why not, though the select one would work, so what am I doing wrong?

    Thanks
    RudeYute

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select Tab

    You change it through the tabcontrol itself, not the tabpage.

    So it would be something like

    tabcontrol1.SelectedIndex = combobox1.selectedindex
    (if the combobox and tabpages indexes match)

    otherwise I am sure from this you can get it working how you need.

    The tab control also has a .SelectedTab property you can set, but you would need to set it to a TabPage object, and its probably going to be easier to use indexes here.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Re: Select Tab

    Wow, I can't believe how wrong I was on that one! Just tried your code and it works perfect!

    Thanks
    RudeYute

  4. #4
    Hyperactive Member
    Join Date
    May 2005
    Posts
    258

    Re: Select Tab

    You can also use TabControl1.TabSelect(PageIndex). I personally like that one better, less code and more concise.
    Currently Using: VS 2005 Professional

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select Tab

    how is it less code? by the amount of characters used????

    TabControl1.SelectedIndex = PageIndex
    TabControl1.TabSelect(PageIndex)

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Re: Select Tab

    This code was working fine, but then the tabs rearranged themselves and so the wrong page opens with the combobox. Is there anyway to lock the tabs so that they don't move? I have tried the lock property but that doesn't work.
    RudeYute

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select Tab

    what do you mean rearrange? you mean tab 0 becomes tab 2 or something like that?

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Re: Select Tab

    Yep.
    RudeYute

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select Tab

    can you post the code you have in the combobox's selectedindex changed event?

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Re: Select Tab

    VB Code:
    1. Private Sub cbGPSSentence_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbGPSSentence.SelectedIndexChanged
    2.         Select Case cbGPSSentence.Text
    3.             Case Is = "$GPGGA"
    4.                 tcResponse.SelectedIndex = cbGPSSentence.SelectedIndex
    5.             Case Is = "$GPGLL"
    6.                 tcResponse.SelectedIndex = cbGPSSentence.SelectedIndex
    7.             Case Is = "$GPGSA"
    8.                 tcResponse.SelectedIndex = cbGPSSentence.SelectedIndex
    9.             Case Is = "$GPGSV"
    10.                 tcResponse.SelectedIndex = cbGPSSentence.SelectedIndex
    11.             Case Is = "$GPRMC"
    12.                 tcResponse.SelectedIndex = cbGPSSentence.SelectedIndex
    13.         End Select
    14.     End Sub
    Have tried a few variations aswell.
    RudeYute

  11. #11
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select Tab

    I dunno man, here is a little sample I did up. Is this basically what you are trying to do?
    Attached Files Attached Files

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Re: Select Tab

    That code does exactly the same. The only difference from your code and my code, is the fact that I have named the tabs differently, which I wouldn't think makes any difference.
    RudeYute

  13. #13
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select Tab

    it doesn't change the order of the tabs though??? unless there is something I am missing here.

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Nov 2004
    Location
    UK
    Posts
    29

    Re: Select Tab

    Beats me!
    RudeYute

  15. #15
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select Tab

    well what im saying is, when you select the first item in the combobox, the first tab is selected. You select the second item in the combobox, the second tab becomes selected, etc...

    they dont change their order though

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width