• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 263
  • Last Modified:

Help with highlighting rows in multiple Grids based on row selected from one Grid

Hi,

I have four DataGrid with data from different tables, but they all have the same SN column,
when I click on a column on either DataGrid, how do I highlight the rows in the other grids with the matching SN value?

Thanks,

Victor
0
vcharles
Asked:
vcharles
  • 3
  • 2
1 Solution
 
vcharlesAuthor Commented:
Hi again,

is it possible to use both SN and country instead of only SN, I will have multiple identical SN
values, therefore will need to add the country column to highlight the appropriate columns in the other grids.

Thanks,

Victor
0
 
Fernando SotoCommented:
Hi Victor;

This code snippet should do what you want. Note that I placed the code in CellClick event so I can get the current row.

Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick

    ' Clear the selection in all the DataGridView's
    DataGridView1.ClearSelection()
    DataGridView2.ClearSelection()

    ' Get the currently select row
    Dim index1 As Integer = DataGridView1.CurrentRow.Index
    ' Select that row in DataGridView1
    DataGridView1.Rows(index1).Selected = True

    ' Get all the row indexs in DataGridView2 That match the criteria
    Dim childRows = From row As DataGridViewRow In DataGridView2.Rows _
                    Where row.Cells("SN").Value = DataGridView1.Rows(index1).Cells("SN").Value AndAlso _
                          row.Cells("CTRY").Value = DataGridView1.Rows(index1).Cells("CTRY").Value _
                    Select row.Index

    ' Select all the matching rows
    For Each idx In childRows
        DataGridView2.Rows(idx).Selected = True
    Next

End Sub

Open in new window

0
 
vcharlesAuthor Commented:
Hi,

Thank You very much, I will try it and get back to you later.

Victor
0
 
vcharlesAuthor Commented:
It works!

Thank You.

Victor
0
 
Fernando SotoCommented:
Not a problem Victor, glad to help.
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

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