Solved

Tab control fire event vb.net 2008

Posted on 2009-05-04
5
580 Views
Last Modified: 2013-11-26
I have a tab control with few tab. how to fire an event when use click on the tab. I need some code in vb.net 2008
0
Comment
Question by:aarontham
5 Comments
 
LVL 1

Expert Comment

by:chuckdsc
ID: 24296852
aarontham,

are  you looking at executing any function when a user changes the tab or when a user clicks on the tab ?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 24298896
You can use SelectedIndexChanged event in the TabControl
    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
 

        Debug.WriteLine(Me.TabControl1.SelectedTab.Name.ToString)
 

    End Sub

Open in new window

0
 

Author Comment

by:aarontham
ID: 24301105
Hi jpaulino,

i just need to populate the datagribview in tab1 when user click on tab1. same with tab2 and tab3.
is that advice to unbound that datagriview in tab1 when user click on tab2?
0
 
LVL 15

Expert Comment

by:JackOfPH
ID: 24301158
Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
 
For Each ctrl As Control In TabControl1.SelectedTab.Controls
            If TypeOf ctrl Is datagridview Then
                Dim dgView as datagridview = ctrl
               
                'Do your staff here...

                Exit For
            End If
        Next

End Sub

post if you have questions...
0
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 24302009
You can check what tab is selected and then fill the appropriate datagridview.
I think you have different datasources for each datagridview, right ?

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged

        Select Case Me.TabControl1.SelectedIndex
 

            Case 0 ' First tab

                Me.DataGridView1.DataSource = ...

            Case 1 ' Second tab

                Me.DataGridView2.DataSource = ...

            Case 2 ' Third tab

                Me.DataGridView3.DataSource = ...

        End Select

    End Sub

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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