If I have a datagridview of say 7 Rows and 27 Columns and if I need to compare the values of cells with another cells how to do it?
Detail:
I need to compare 1st Row cell value with rest of the 6 rows cell values, same thing repeats for 2nd Row for rest 5 row, again same comparison needed for 3rd row with rest 4 rows. Basically It is row wise comparison
ROW1-> 2 2 2 4 4 6 6 8 8 8 7 7
ROW2-> 1 1 1 7 7 7 6 9 9 9 7 7
ROW3-> 1 1 3 3 3 3 5 5 5 0 0 0
ROW4-> 2 2 2 0 0 0 0 1 1 1 7 7
ROW5-> 0 0 0 3 3 3 4 4 4 8 8 8
Now I want to color those Cell whose values are repeating. Any idea will be a great help for me.
Here is the code
public void check_conflict()
{
int rowCount=dataGridView1.RowCount;
int colCount=dataGridView1.ColumnCount;
string val1;
int c = 1;
for (int k = 0; k < rowCount - 1; k++)
{
for (int i = 1; i < colCount; i++, c++)
{
val1 = Convert.ToString(dataGridView1.Rows[k].Cells[i].Value);
for (int j = 1; j < rowCount - 1; j++)
{
string val2 = Convert.ToString(dataGridView1.Rows[j].Cells[i].Value);
if (val1 == val2 && (val1 != "" && val2 != ""))
{
DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.Red;
dataGridView1.Rows[j].Cells[i].Style = CellStyle;
}
}
}
}
}
Problem I facing with code is it is only comparing 1 Row with others