Link to home
Start Free TrialLog in
Avatar of bhlabelle
bhlabelleFlag for Afghanistan

asked on

Finding the Active datagridview in vb.net

Well I had a solution, but I want to reduce how much coding I do ('cause I'm no good at coding).
Basically I have a windows applicaton with a bunch of forms, and on each form is a tab control, and on each tab control is a bunch tabs all with different datagridviews, and the number keeps growing!

I found some code that nicely prints the datagridviews, and I wanted to be able to set "DataGridView1" (which is declared as "Private DataGridView1 As DataGridView") with the current datagridview the user is on.  

From the question I previously asked, I was able to get the name of the SelectedTab from the TabControl, which is the active control (the datagridview that is on the SelectedTab is NOT the active control as was suggested in the related question).  Then I have an "if" statement to set "DataGridView1":

Dim MyActiveTab As String = TabControl1.SelectedTab.Name
If MyActiveTab = "TabPage1" Then
            DataGridView1 = PartnershipsDataGridView
ElseIf MyActiveTab = "TabPage2" Then
            DataGridView1 = PartnersDataGridView
ElseIf MyActiveTab = "TabPage3" Then
etc, etc. and so on.

I do this because I know the name of the datagridview on each tab page.  Problem is I don't want to do this for every datagridview I add on every form ('cause I'm adding them all the time).  Any help/thoughts would be much appreciated.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Is there a one-to-one relationship between TabPage and DataGridView (one DataGridView per tab)?
Avatar of bhlabelle

ASKER

Yes, one DataGridView per TabPage
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now I am (more)Learned..thanks for your quick response!