this is my datagrid
i tried the following code for removing the duplicate row in datagridview
public static DataTable items = new DataTable();
items.Columns.Add("Backsn");
items.Columns.Add("Oprn Name");
for (int i = 0; i < dataGridView1.Rows.Count;i++ )
{
DataRow rw = items.NewRow();
rw[0] = dataGridView1.Rows[i].Cells[2].Value.ToString();
rw[1] = dataGridView1.Rows[i].Cells[8].Value.ToString();
items.Rows.Add(rw);
}
dataGridView2.DataSource = items;
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
int k = 0;
for (int j = 0; j < dataGridView2.Rows.Count; j++)
{
if (dataGridView2.Rows[i].Cells[0].Value == dataGridView2.Rows[j].Cells[0].Value && dataGridView2.Rows[i].Cells[1].Value == dataGridView2.Rows[j].Cells[1].Value)
{
if (k != 0)
{
items.Rows.RemoveAt(j);
dataGridView2.DataSource = items;
}
k= k+1;
}
}
}
But no luck. I should get result like below.Please help me to solve.