Solved

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

Posted on 2014-03-09
5
256 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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