Hi everyone,

I need help changing the background color for duplicated items in datagridview...
I am using this code but it makes all duplicates same color what I want is only same duplicates should have the same color, different duplicates should have different colors, as shown below ;
Imagen

the code I am using :

Código: Seleccionar todo

public void HighlightDuplicate(DataGridView grv)
{
    for (int currentRow = 0; currentRow < grv.Rows.Count - 1; currentRow++)
    {
        DataGridViewRow rowToCompare = grv.Rows[currentRow];
        for (int otherRow = currentRow + 1; otherRow < grv.Rows.Count; otherRow++)
        {
            DataGridViewRow row = grv.Rows[otherRow];

            bool duplicateRow = true;
            if (!rowToCompare.Cells["User"].Value.Equals(row.Cells["User"].Value))
            {
                duplicateRow = false;
                break;
            }
            if (duplicateRow)
            {
                rowToCompare.DefaultCellStyle.BackColor = Color.Red;
                rowToCompare.DefaultCellStyle.ForeColor = Color.Black; 
                row.DefaultCellStyle.BackColor = Color.Red;
                row.DefaultCellStyle.ForeColor = Color.Black; 
            }
        }
    }
}
thanks in advanced