• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 597
  • Last Modified:

how do I use tab control on vb2008

Have a tab control with 6 tabs.  When I click a button I want  tab index 0 to be displayed.  I have tried tabcontrol.selectedindex =0 and tabcontrol.selectedtab= tabpage1.  In both instances, the tab page is not selected unless it is higher than the current selected tab.  For example, if tab page 0 is visible and I use tabcontrol.selectedindex= 3, tab page is displayed properly.  However, if tab page 3 it displayed, and I use selectedindex = 0 then nothing happens.  It only changes if the new selectedindex is higher than the current selectedidnex.  Anyone have any suggestions?
0
GCCal
Asked:
GCCal
  • 2
  • 2
2 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
I can't reproduce the problem...can you give more details about your app?

Works great for me:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Button1 is on TabPage3:
        TabControl1.SelectedIndex = 0 ' <-- First TabPage becomes selected!
    End Sub

End Class

Open in new window

0
 
MukeshsinghgCommented:
this is working---

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '--Currently TabPage6 is selected
        TabControl1.SelectedTab = TabControl1.TabPages("TabPage1")
        '---------Now TabPage1 is selected---------
    End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '--Currently TabPage6 is selected
        TabControl1.SelectedTab = TabControl1.TabPages("TabPage1")
        '---------Now TabPage1 is selected---------
    End Sub

Open in new window

0
 
GCCalAuthor Commented:
Idle_Mind and Mukeshsinqhq:

Actually neither one of your suggestions worked when I first tried them.  I then delete the button and placed a new button on the workspace and then both suggestions worked properly.  Don't understand why this happens, but I remember similar things happening a couple time before.  Had to replace the control for the code to work properly.

Thanks, and I will split since both suggestion were functional.

Happy Holidays.........
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
That can happen when you cut and paste a control from one place to another on the form.  When you do this it removes the "Handles xxx.yyy" portion of the code thus "un-wiring" it from the event.  To fix it WITHOUT placing a new one, click on the button then the "Lightning Bolt" Icon in the Properties Pane to get the events.  Next find the "Click" entry and press the DropDown to the right.  You should see an entry like "Button1_Click" that you can select to "re-wire" that sub to the event.
0
 
GCCalAuthor Commented:
Thanks for the info, Idle_Mind.  I didn't know that and it is a good tidbit to file away in this old mind.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now