OK, Since I had fun with my linguistic pedantry and feel a bit guilty for it, here is a solution to what I think the problem is. It assumes a form with a (WinForms) DataGridView loaded; it highlights the whole column if the column contains any cells with duplicate data. It's a test app so create a new project, add a DataGridView to the form, pull the relevant parts from the code below and play with it:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DGV_Tester
{
public partial class Form1 : Form
{
DataGridViewCellStyle m_hilightStyle = null;
public Form1()
{
InitializeComponent();
SetHilightCellStyle();
}
private void SetHilightCellStyle()
{
m_hilightStyle = dataGridView1.DefaultCellStyle.Clone();
m_hilightStyle.ForeColor = Color.Red;
m_hilightStyle.BackColor = Color.Yellow;
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
ValidateGrid();
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = MyData.Values;
ValidateGrid();
}
private void ValidateGrid()
{
foreach (var colNum in Enumerable.Range(0, dataGridView1.Columns.Count))
{
bool matchFound = false;
string keyValue = null;
foreach (var rowNum in Enumerable.Range(0, dataGridView1.RowCount))
{
keyValue = dataGridView1.Rows[rowNum].Cells[colNum].Value.ToString();
foreach (var targetRowNum in Enumerable.Range(rowNum + 1, dataGridView1.RowCount - 1 - rowNum))
if (keyValue == dataGridView1.Rows[targetRowNum].Cells[colNum].Value.ToString())
{
matchFound = true;
break;
}
}
HighlightColumn(colNum, matchFound);
}
}
private void HighlightColumn(int colNum, bool matchFound)
{
dataGridView1.Columns[colNum].DefaultCellStyle = matchFound ? m_hilightStyle : dataGridView1.DefaultCellStyle;
}
}
}