Removing duplicates from a ListView 
Author Message
 Removing duplicates from a ListView

I have a ListView called ListView1, and I want to remove all the
duplicates from the list, like so:

Before:
-------------
Apple
Banana
Orange
Banana
Apple
Pear
-------------

After:
-------------
Apple
Banana
Orange
Pear
-------------

Can someone please provide me with a function that removes any
duplicates?  Somebody must have written one.

Thanks,

Jules

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Fri, 23 Sep 2005 02:11:37 GMT  
 Removing duplicates from a ListView

Quote:
> I have a ListView called ListView1, and I want to remove all the
> duplicates from the list, like so:

> Before:
> -------------
> Apple
> Banana
> Orange
> Banana
> Apple
> Pear
> -------------

> After:
> -------------
> Apple
> Banana
> Orange
> Pear
> -------------

> Can someone please provide me with a function that removes any
> duplicates?  Somebody must have written one.

Not yet, but now:  ;-)

      Dim i, j As Integer
      With Me.ListView1
         Do Until i > .Items.Count - 2
            Dim text As String = .Items(i).Text
            j = i + 1
            Do Until j > .Items.Count - 1
               If .Items(j).Text = text Then
                  .Items.RemoveAt(j)
               Else
                  j += 1
               End If
            Loop
            i += 1
         Loop
      End With

--
Armin



Fri, 23 Sep 2005 03:36:03 GMT  
 Removing duplicates from a ListView


Quote:
> I have a ListView called ListView1, and I want to remove all the
> duplicates from the list, like so:

depending on circumstance, it might be a lot easier not to let the dupes get
in the list in the first place ...
Quote:
> Before:
> -------------
> Apple
> Banana
> Orange
> Banana
> Apple
> Pear
> -------------

> After:
> -------------
> Apple
> Banana
> Orange
> Pear
> -------------

> Can someone please provide me with a function that removes any
> duplicates?  Somebody must have written one.

> Thanks,

> Jules

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Fri, 23 Sep 2005 04:36:51 GMT  
 Removing duplicates from a ListView
De-duping algorithms suck, their slow and buggy (most times). So kill the
dupes before they exist. Just create a collection, and when you add items to
the list, add them to the collection as well. Use the possible duplicate
data as the "Key" parameter for the item being added to the collection. When
you add a duplicate, it throws an exception and thus circumventing your code
that adds the duplicate to the list.

Just make sure you add the item to the collection *before* you add it to the
list.

of course, this method doubles the memory required.

An alternative (less memory / more proc time) would be to loop through the
items as they are added, but this method is about 1000x slower.

HTH,
Jeremy


Quote:
> I have a ListView called ListView1, and I want to remove all the
> duplicates from the list, like so:

> Before:
> -------------
> Apple
> Banana
> Orange
> Banana
> Apple
> Pear
> -------------

> After:
> -------------
> Apple
> Banana
> Orange
> Pear
> -------------

> Can someone please provide me with a function that removes any
> duplicates?  Somebody must have written one.

> Thanks,

> Jules

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Fri, 23 Sep 2005 04:59:55 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Removing duplicates names but not losing their other fields

2. Automate removing duplicate records

3. How to remove duplicate messages from public folder

4. Remove Duplicate Task

5. Remove duplicates from list

6. How to remove duplicates in a range of cells

7. Remove Duplicate Paragraphs?

8. Removing duplicate records in SQL

9. Remove duplicates from ArrayList????

10. Removing Duplicate Records

11. Removing Duplicate Records VB6/Access2000

12. Searching and removing Duplicate records

 

 
Powered by phpBB® Forum Software