Avatar of Wilder1626
Wilder1626
Flag for Canada asked on

VB.NET - Delete duplicated rows

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
Visual Basic.NET

Avatar of undefined
Last Comment
Wilder1626

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kimputer

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Wilder1626

ASKER
Thanks
This is working great.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23