+ Reply to Thread + Post New Thread
Results 1 to 5 of 5

Thread: Remove Duplicate Items

  1. #1
    Noobie
    Join Date
    Apr 2008
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Remove Duplicate Items

    Hey i am trying to remove duplicate items from 2 listboxes.... i have the code to remove duplicate items from one list box...i'm trying to build a database of names and i dont want the names to be on there twice. So I'm wanting one list to be the database or names and the other list to be new names.. Lets say i have the database list that has 1,000 names and the other list has 200 names...I want to have a button that when it is clicked it will remove any names from the second list if it is already in the database list....here is the code i have to remove duplicates

    Public Sub RemoveDuplicateItem(ByVal listboxName As ListBox)
    listboxName.Sorted = True
    listboxName.Refresh()
    Dim index As Integer
    Dim itemcount As Integer = listboxName.Items.Count

    If itemcount > 1 Then
    Dim lastitem As String = listboxName.Items(itemcount - 1)

    For index = itemcount - 2 To 0 Step -1
    If listboxName.Items(index) = lastitem Then
    listboxName.Items.RemoveAt(index)
    Else
    lastitem = listboxName.Items(index)
    End If
    Next
    End If
    End Sub

    Any suggestions or a better way to do this?

  2. Shorten URL    SEO Services    Buy Xrumer

    Sponsored Links

  3. #2
    Noobie
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Get rid of that removeduplicates sub. All you need to do to remove duplicates is to add a couple lines to the code that you're using to load the list.

    For example:

    if listbox1.items.contains(strItem) = false then
    listbox1.items.add(strItem)
    end if

    It's basically saying if the list doesn't already contain strItem then add it.

  4. #3
    Noobie
    Join Date
    Apr 2008
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Post the code you're using to load the list in the first place and I'll modify it to work as you need it to.

  5. #4
    Noobie
    Join Date
    Aug 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It's better to prevent adding duplicates to listbox than removing it later.

  6. #5
    Registered Member SalesPort's Avatar
    Join Date
    Jun 2010
    Location
    where ever there is a good living to be made
    Posts
    84
    Thanks
    6
    Thanked 4 Times in 3 Posts

    Default

    he has them added already

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts