Can't get TabControl TabPages click event to work

I created a Smart Device project in VB 2005.

I added a TabControl with 5 TabPages on it.

I added various controls in the tab page, but I need to get some code to work and have to test it.

I installed a click event on the tab, but it doesn't work since a breakpoint on the code inside the event doesn't catch the click. I've tryed other events as well, but none of them are working either.

Can anyone give me an idea as to why this isn't working

Thanks.



Answer this question

Can't get TabControl TabPages click event to work

  • ciir1

    Hi Tony,

    Nice to know that you were able make progress.

    The TabControl does not have a Click event. In fact you cannot add any control onto a TabControl that does not have any Tabpages.

    I have a sugesstion that might help improve readablility of your code. You could use the

    TabControl1.TabPages(TabControl1.SelectedIndex).Name

    in the Select clause and specify the names of the TabPages in the Case statements.

    Thanks and regards,

    Jagadisk


  • Rahul Kulshreshtha MscIT

    I picked it from the list since I can never do it myself. Such obscure code I have hardly ever seen. I'm a Basic/FoxPro programmer for 30 years, not a .NET programmer. Whoever invented this stuff ought to be drowned in their own code. Object orientation is going backward in my opinion. At any rate...

    I still couldn't get the click event to work right, but I did find that after I clicked on the tab and the page opened, then I clicked on the page itself, I was able to get the click event to work. It looks like the tab doesn't have a click event, it's the page itself. I think this is a Microsoft bug.

    However I did come up with a solution thanks to other suggestions. The "SelectedIndexChanged" event was the answer. It wasn't the best way to go since we have to use index numbers instead of names, but it works. Here's the code:

    Private Sub TabControl_SelectedIndexChanged(ByVal sender As
    Object, ByVal e As System.EventArgs) Handles
    TabControl.SelectedIndexChanged
    Select Case Me.TabControl.SelectedIndex
    Case 0
    If Not glFirstTime Then
    TabWOGo()
    Else
    glFirstTime = f
    End If
    Case 1
    TabPartsGo()
    Case 2
    TabIDGo()
    Case 3
    TabStepsGo()
    Case 4
    TabTestsGo()
    Case 5
    TabHistGo()
    End Select
    End Sub

    The "If Not glFirstTime Then" code has to be in there because when the form initializes, the code in the first tab has to be excluded from running.

    CU


  • hixxy

    Hi Tony,

    Did you add the tabcontrol event handler via the VS designer or did you "manually" typed in the event havdler function

    Does your event handler look like this (please note the Bold and underlined text):

    Private Sub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click

    Thanks and regards,

    Jagadisk


  • efarook

    Thanks for the suggestion.

    Here is the code I am using now. The advantage of using names instead of numbers is that the frist time through, when the form initializes, name is "" and the "glFirstTime" code doesn't have to be used.

    Private Sub TabControl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl.SelectedIndexChanged

    Dim lcName As String

    lcName = TabControl.TabPages(TabControl.SelectedIndex).Name

    Select Case lcName

    Case "TabWO"

    TabWOGo()

    Case "TabPart"

    TabPartsGo()

    Case "TabIDList"

    TabIDGo()

    Case "Tab Steps"

    TabStepsGo()

    Case "TabTests"

    TabTestsGo()

    Case "TabWOList"

    TabHistGo()

    End Select

    End Sub


  • Can't get TabControl TabPages click event to work