Home » winforms » WinForms – Change The Active Tab

WinForms – Change The Active Tab

misc_vol2_056 This question came in last Friday:

I’m trying to code a windows form in vb.net 2005. In my form I have 2 TabControls and a command button. The button is in the first TabControl, so what I want to do, is that when I click the button, in the first TabControl, the second TabControl gets opened.

I’m assuming here that what is really being asked is, “How do I change the active tab in a TabControl from some other event, like a button click in a tab?”

Given a form that looks like this:

image

Create a Button Click event handler for “Button1” and set the SelectedIndex property of the TabControl to 1 to activate, “TabPage2”

    Private Sub Button1_Click( _
       ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles Button1.Click
        TabControl1.SelectedIndex = 1
    End Sub

If you don’t know the index of the tab you want to activate, you can use the tab object instead:

    Private Sub Button1_Click( _
       ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles Button1.Click
        TabControl1.SelectedTab = TabPage2
    End Sub

 

Other post in winforms

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • Windows Forms – Passing Parameters at RuntimeWindows Forms – Passing Parameters at Runtime I received the following question over the weekend: I've made a C# form application and I need to send a report name at runtime. How do I add an incoming parameter to the command line? […]
  • One Form with Multiple TablesOne Form with Multiple Tables I received the following question a few days ago: “I am trying to use three tables from the same dataset in one form that I am creating in vs.net winforms my problem I guess is the setup […]
  • VB.NET Processing Before WinForm DisplayVB.NET Processing Before WinForm Display I woke up this morning to an interesting question. “Using VB.net 2008, I want my project to be a Windows Forms Application, but upon startup, I want to check a few files to see if they […]
  • AjaxToolKit TabControl Disabled TabAjaxToolKit TabControl Disabled Tab I just finished an interesting project that involved the AjaxToolKit's Tab control.  The first part of my assignment was to make the Tabs start about 160 pixels to the right of the left […]
  • WinForms – Database Changes not sticking.WinForms – Database Changes not sticking. Saturday afternoon I spent trying to get a Windows Forms application to add data to a database.  It all seemed to work correctly.  Add changes, no errors.  Close window, […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer. His commitment to quality through test driven development, vast knowledge of C#, HTML, CSS and JavaScript as well as his ability to mentor younger programmers and his passion for Agile/Scrum as defined by the Agile Manifesto and the Scrum Alliance will certainly be an asset to your organization.

2 Pingbacks/Trackbacks