Problem with Tabs

johnadonaldson

Well-known member
Joined
Nov 9, 2005
Messages
48
Programming Experience
10+
I can click on the body of a page and the CLICK function works. What function do I need to use
to achieve the same result when I Click on the Tab itself.



 
I think TabControl.SelectedIndexChanged event is what you are searching for.
 
OK, how would I use it. I need to be able to click on the Tab itself, have varibles set for that Tab. Click on a different Tab and have varibles for that
Tab be set.

Hope I am explaining what I want to do correctly.
 
Are you looking for this?

VB.NET:
    Private Sub Tab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        If TabControl1.SelectedIndex = 0 Then
            'set variables for Tab 1
        End If
        If TabControl1.SelectedIndex = 1 Then
            'set variables for Tab 2
        End If
    End Sub
 
David..... Getting closer. This works upto a point. Where it fails is where I have multi-tab configuration. What I have is two rows of tabs. I have say three tabs on the top row. Under this I have say 2 tabs assocaited with each Tab on the top row. So I need to beable to select a top tab then when I select a bottom assocaited tab, be able to detect that I selected the associated tab.

Top Row Tab1, Tab2, Tab3, Tab 4
Bottom Row
Tab5, Tab6 - associated with Tab1
Tab7, Tab8 - associated with Tab2
Tab9, Tab10 - assocaited with Tab3

I was able to change the format to:

PrivateSub Tab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl2.SelectedIndexChanged
If TabControl2.SelectedIndex = 0 Then
'set variables for Tab 1
MantisseTab = 1
Me.TextBox4.Text = "TabPage5"
Me.TextBox34.Text = "MantisseTab1"
EndIf
If TabControl2.SelectedIndex = 1 Then
'set variables for Tab 1
MantisseTab = 2
Me.TextBox4.Text = "TabPage6"
Me.TextBox34.Text = "MantisseTab2"
EndIf
EndSub

Guess what I am asking is I need to be able to detect that I selected Tab 5,6 under Tab1, Tab 7,8 under Tab2 and Tab 9,10 under Tab3.
 
Last edited:
Depends on the TabControl

If tabs 5 - 10 are indexes of TabControl2 then the answer is 'yes' just add more 'if statements' (or Select Case structure would work also).

If tab 5 & 6 are indexes of a different TabControl (say TabControl3) then you would have a seperate sub for TabControl3.SelectedIndexChanged.
Each index for a new TabControl starts with 0, so you would duplicate your code and change TabControl2 to whatever tabControl 5 & 6 are on (check 'NAME' under properties)

Am I making any sense?


case Select:

VB.NET:
         Select Case TabControl2.SelectedIndex
            Case Is = 0
                MantisseTab = 1
                Me.TextBox4.Text = "TabPage5"
                Me.TextBox34.Text = "MantisseTab1"
            Case Is = 1
                MantisseTab = 2
                Me.TextBox4.Text = "TabPage6"
                Me.TextBox34.Text = "MantisseTab2"
            Case Is = 2

        End Select

 
David,
Figured it out. Thanks for the help. The problem was I was trying to use another instance of the sub

Private Sub Tab_Click1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl2.SelectedIndexChanged
If TabControl2.SelectedIndex = 0 Then
'set variables for Tab 1
MantisseTab = 1
Me.TextBox4.Text = "TabPage6"
Me.TextBox34.Text = "MantisseTab1"
End If
If TabControl2.SelectedIndex = 1 Then
'set variables for Tab 1
MantisseTab = 2
Me.TextBox4.Text = "TabPage7"
Me.TextBox34.Text = "MantisseTab2"
End If
End Sub

And I was not changing the Tab_Click1 to Tab_Click2. VB.NET complained until I did. Now it is working like it should.
Thanks for the help and direction.

 
Last edited:
Back
Top