Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Find and remove Duplicate rows from DatagridView

$
0
0

Hi,

I have coded for find and remove the duplicate rows from datagrid view based on ID column(See the snap). But it not working...

Thanks to any one could assist me...

 private void DelDuplicateData()
        {
            List<string> list1 = new List<string>();
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                string str = dataGridView1.Rows[i].Cells[2].Value.ToString();
                if (!list1.Contains(str))
                {
                    list1.Add(dataGridView1.Rows[i].Cells[2].Value.ToString());
                }
                else
                {
                    dataGridView1.Rows.Remove(dataGridView1.Rows[i]);
                }

            }
           
        }


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>