forum

Home / DeveloperSection / Forums / Compare datagridview1 and datagridview2 and mark same values c#

Compare datagridview1 and datagridview2 and mark same values c#

Samuel Fernandes 15728 27-Jan-2014

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);
       }
   }
}

c# c# 
Updated on 27-Jan-2014

Can you answer this question?


Answer

1 Answers

Liked By