I have this DataGridView2 with data in it. I would like to delete all duplicated rows and leave only one of each.
Ex: Based on above picture, it would remove one of the CustomerId 2. I must say that the grid is not sorted. So it may not be one after the other.
This is what i have so far. But it only look at row.cell(1). It should account for all columns, no matter the number of columns the DataGridView2 could have.
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles btnRemoveDuplication.Click For Loop1 As Integer = 0 To DataGridView2.Rows.Count - 2 For Loop2 As Integer = Loop1 + 1 To DataGridView2.Rows.Count - 2 If DataGridView2.Rows(Loop1).Cells(1).Value = DataGridView2.Rows(Loop2).Cells(1).Value Then DataGridView2.Rows.RemoveAt(Loop2) End If Next Next End Sub
This is working great.