Here's a
pseudo-code solution just to give you a simple algorithm, which should put you on the right lines. The actual re-colouring bit I can't remember the code for off the top of my head so take the essence of what it is doing rather than the actual code. If you're still stuck, then please give some more details and your own code so far.
List<int> distinctMatchingValues = (from a in listAValues.Distinct()
join b in listBValues.Distinct() on a equals b
select a).ToList();
Dictionary<int, Color> palette = new Dictionary<int, Color>();
foreach(var i in distinctMatchingValues)
{
palette.Add(i, GetNextOrRandomColor());
}
foreach(var column in gridAColumns)
{
foreach(var cell in column)
{
cell.Style = new DataGridViewStyle{ BackColor = palette[cell.Value] };
}
}
foreach(var column in gridBColumns)
{
foreach(var cell in column)
{
cell.Style = new DataGridViewStyle{ BackColor = palette[cell.Value] };
}
}