troubleshooting Question

VB.NET - Delete duplicated rows

Avatar of Wilder1626
Wilder1626Flag for Canada asked on
Visual Basic.NET
2 Comments1 Solution10 ViewsLast Modified:
Hi all

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

Open in new window


Thank you for your help
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros