I have a datagridview that contains many rows, some of this rows have duplicate values.
This datagridview is addable .. I add and remove rows frequently.
I want to count rows every time i add row or remove it, and consider duplicate rows as a single.
I tried this code:
int total = 0;
for (int currentRow = 0; currentRow < dataGrid_Target.Rows.Count - 1; currentRow++)
{
DataGridViewRow rowToCompare = dataGrid_Target.Rows[currentRow];
for (int otherRow = currentRow + 1; otherRow < dataGrid_Target.Rows.Count; otherRow++)
{
DataGridViewRow row = dataGrid_Target.Rows[otherRow];
if (!row.IsNewRow)
{
if (!Convert.ToString(rowToCompare.Cells[0].Value).Equals(Convert.ToString(row.Cells[0].Value)))
{
total++;
}
else
{
total = total+1;
}
}
}
}
But it doesn't help.