The following code is how I check for duplicates in a List box. This is
simple enough as there is only one column of stuff to check.
' Check for Duplicates
' Search listbox (from last to first)
For cntr = lbDwgList.Items .Count - 1 To 1 Step -1
' If next item is a duplicate -> Remove It
If lbDwgList.Items (cntr) = lbDwgList.Items (cntr - 1) Then _
lbDwgList.Items .RemoveAt(cntr)
Next
But I've a ListView (2 columns) that I want to check for duplicates. Having 2
columns is not the issue as I can check for a string of Col1+Col2.
But like my Listbox example, I want to check Last Item to First Item (bottom
to top). Both my ListBox and ListViews are sorted Ascending.
In a ListView, how do I do a reverse check (never having done it before).
The following of course does not work (because it doesn't search last to
first). And it returns an Error anyways. (:
' Check for Duplicates
i = lvModDwgs.Items .Count
For Each LItem In lvModDwgs.Items
' If next item is a duplicate -> Remove It
If LItem.SubItems( i).ToString = LItem.SubItems( i + 1).ToString Then _
lvModDwgs.Items .RemoveAt(i)
i = i + 1
Next
Anyone have any suggestions?
Regards,
Bruce
simple enough as there is only one column of stuff to check.
' Check for Duplicates
' Search listbox (from last to first)
For cntr = lbDwgList.Items .Count - 1 To 1 Step -1
' If next item is a duplicate -> Remove It
If lbDwgList.Items (cntr) = lbDwgList.Items (cntr - 1) Then _
lbDwgList.Items .RemoveAt(cntr)
Next
But I've a ListView (2 columns) that I want to check for duplicates. Having 2
columns is not the issue as I can check for a string of Col1+Col2.
But like my Listbox example, I want to check Last Item to First Item (bottom
to top). Both my ListBox and ListViews are sorted Ascending.
In a ListView, how do I do a reverse check (never having done it before).
The following of course does not work (because it doesn't search last to
first). And it returns an Error anyways. (:
' Check for Duplicates
i = lvModDwgs.Items .Count
For Each LItem In lvModDwgs.Items
' If next item is a duplicate -> Remove It
If LItem.SubItems( i).ToString = LItem.SubItems( i + 1).ToString Then _
lvModDwgs.Items .RemoveAt(i)
i = i + 1
Next
Anyone have any suggestions?
Regards,
Bruce
Comment