How to fire tabControl.SelectedIndexChanged when form is loaded?

Posted on 2012-09-18
Last Modified: 2012-09-18
Hi Experts,

I have a form that has a tabControl with 2 tabs on it.

I have some code in the tabControl.SelectedIndexChanged event.

But when the form loads the tabControl.SelectedIndexChanged event does not fire.

How can I fire the tabControl.SelectedIndexChanged event (effectively clicking the first tab) when the form loads?

Question by:LeighWardle
    LVL 85

    Accepted Solution

    In the Load() event, set SelectedIndex to -1, then back to 0 (zero).

    Make sure your code can handle the -1 value though:
    Public Class Form1
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            TabControl1.SelectedIndex = -1
            TabControl1.SelectedIndex = 0
        End Sub
        Private Sub TabControl1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
            If TabControl1.SelectedIndex <> -1 Then
                Debug.Print("SelectedIndexChanged: " & TabControl1.SelectedIndex)
            End If
        End Sub
    End Class

    Open in new window

    LVL 1

    Author Closing Comment

    Idle_Mind - a brilliant solution!

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Best way to accomplish this task? 3 66
    sql server/ 15 26 check for multiple values 5 29
    Performance enhancement 39 17
    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video discusses moving either the default database or any database to a new volume.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now