I have a problem with comparing datagridviews.
I need to compare 2 datagridviews and if values are same, mark them or do something. (I import values from excel)
I cant use linq it's slow.
I try this but it seems I cant get it to work:
for (int currentRow = 0; currentRow < grv.Rows.Count; currentRow++)
{
var rowToCompare = grv.Rows[currentRow]; // Get row to compare against other rows
// Iterate through all rows
//
foreach (var row in grv.Rows)
{
if (rowToCompare.equals(row) continue; // If row is the same row being compared, skip.
bool duplicateRow = true;
// Compare the value of all cells
//
for (int cellIndex; cellIndex < row.Cells.Count; cellIndex++)
{
if (!rowToCompare.Cells[cellIndex].Value.equals(row.Cells[cellIndex].Value))
{
duplicateRow = false;
break;
}
}
if (duplicateRow)
{
grv.Rows.Remove(row);
}
}
}
Pravesh Singh
27-Jan-2014Try this :
This should color duplicates in red. Be sure that both gridview have the same cell number.