Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

Tab control fire event vb.net 2008

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
aarontham
Asked:
aarontham
1 Solution
 
chuckdscCommented:
aarontham,

are  you looking at executing any function when a user changes the tab or when a user clicks on the tab ?
0
 
jpaulinoCommented:
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
 
aaronthamAuthor Commented:
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
 
JackOfPHCommented:
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
 
jpaulinoCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now