Solved

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

Posted on 2014-03-09
5
253 Views
Last Modified: 2014-03-10
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
Comment
Question by:vcharles
  • 3
  • 2
5 Comments
 

Author Comment

by:vcharles
Comment Utility
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
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
 

Author Comment

by:vcharles
Comment Utility
Hi,

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

Victor
0
 

Author Closing Comment

by:vcharles
Comment Utility
It works!

Thank You.

Victor
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem Victor, glad to help.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

9 Experts available now in Live!

Get 1:1 Help Now