DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: HELP!! Delete duplicates from listview

  1. #1
    Join Date
    Apr 2007
    Posts
    3

    HELP!! Delete duplicates from listview

    I have several listview boxes which are filled via a stored procedure that joins several tables. I do not want to retrieve this data using separate stored procedures because I don't want to make that many trips to the database.

    As a result of the joins, some listviews contain duplicates. I need to be able to remove those duplicates in each listview box.

    I tried searching the Internet for what I thought would be an easy item to find. I am coming up with Zip!! (or code that works at any rate).

    Can someone give me a code example of how this would be done?

    Any help will be greatly appreciated!

  2. #2
    Join Date
    Apr 2007
    Posts
    20
    Try this.

    Code:
    Private Sub Command1_Click()
    Dim i As Long, j As Long
    
        With ListView1
            For i = 1 To .ListItems.Count
                For j = .ListItems.Count To (i + 1) Step -1
                    If .ListItems(j) = .ListItems(i) Then
                        .ListItems.Remove j
                    End If
                Next
            Next
        End With
    
    End Sub

  3. #3
    Join Date
    Apr 2007
    Posts
    3
    Quote Originally Posted by Angelo88
    Try this.

    Code:
    Private Sub Command1_Click()
    Dim i As Long, j As Long
    
        With ListView1
            For i = 1 To .ListItems.Count
                For j = .ListItems.Count To (i + 1) Step -1
                    If .ListItems(j) = .ListItems(i) Then
                        .ListItems.Remove j
                    End If
                Next
            Next
        End With
    
    End Sub
    Thank you so much, Angelo88. That solved the problem beautifully!!

  4. #4
    Join Date
    Feb 2004
    Location
    Sydney, Australia
    Posts
    498
    ... or look at DISTINCT in your SELECT

  5. #5
    Join Date
    Apr 2007
    Posts
    3
    Thanks for your response. I couldn't in this particular instance because I had many tables that were joined.

  6. #6
    Join Date
    Feb 2004
    Location
    Sydney, Australia
    Posts
    498
    Suggest all you need is to put 'DISTINCT' after the first 'SELECT' ....

    Greg

Similar Threads

  1. Replies: 1
    Last Post: 09-16-2006, 07:37 PM
  2. Replies: 1
    Last Post: 06-09-2006, 05:21 PM
  3. SQL 2000 Delete Duplicates
    By Mike Kopa in forum Database
    Replies: 3
    Last Post: 12-31-2000, 11:03 AM
  4. To delete the scroll bars in a listview
    By Emmanuel Durand in forum VB Classic
    Replies: 0
    Last Post: 05-10-2000, 11:55 AM
  5. To delete the scroll bars in a listview
    By Emmanuel Durand in forum VB Classic
    Replies: 0
    Last Post: 05-10-2000, 11:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center