?
Solved

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

Posted on 2014-03-09
5
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:vcharles
ID: 39916084
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 63

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 39916301
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
ID: 39916377
Hi,

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

Victor
0
 

Author Closing Comment

by:vcharles
ID: 39916909
It works!

Thank You.

Victor
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39917082
Not a problem Victor, glad to help.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

770 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