i have a list of record that already populated but my problems is How to find out if there are any duplicates? VB.NET

If you just want to know if there are duplicate items in the listview you can use this function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

   Dim ListView As New ListView
   Dim ListViewItem As ListViewItem

   For i = 1 To 3
      ListViewItem = ListView.Items.Add("Item")
      ListViewItem.SubItems.Add(CStr(i))
   Next

   If ListViewContainsDuplicates(ListView, 0) Then
       MsgBox("SubItem 0 has duplicate values")
   End If

   If ListViewContainsDuplicates(ListView, 1) Then
      'will not be called.
      MsgBox("SubItem 1 has duplicate values")
   End If

End Sub

Private Function ListViewContainsDuplicates(ByVal listView As ListView, ByVal subItemIndex As Integer) As Boolean

   'Get a distinct count of the subitem 
   Dim DistinctCount As Integer = (From Item In listView.Items _
                                   Select CType(Item, ListViewItem).SubItems(subItemIndex).Text _
                                   Distinct).Count

   'If the distinct count is not equal to the total listview count
   'then there are duplicate values.
    Return DistinctCount <> listView.Items.Count

End Function

Hi, Unhnd Exception nice It works... Thank you for your very appreciate efforts.

Edited 5 Years Ago by TIP.Synergy: n/a

This question has already been answered. Start a new discussion instead.