3
Contributors
3
Replies
13
Views
6 Years
Discussion Span
Last Post by TIP.Synergy
0

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
0

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

Edited by TIP.Synergy: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.