Results 1 to 5 of 5

Thread: Remove Duplicate Items in Listbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    14

    Question Remove Duplicate Items in Listbox

    Hello, Im trying to remove duplicate items in listbox.

    My list box looks like this.

    row 1
    row 1
    row 2
    row 2
    row 3
    row 3
    row 4
    row 4

    And I would like to remove the duplicated row. How can I do this?

    I tried Me.ListBox1.Items.Remove("row 1") but that will remove both row 1's.

    Thankz.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Remove Duplicate Items in Listbox

    How did the data get into the ListBox in the first place?

  3. #3
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,754

    Re: Remove Duplicate Items in Listbox

    I think where jmcilhinney is going is that you can check to see if the item is in the list before you add it.

    Hey jmcilhinney are you watching our Super Bowl? What time is it on there?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2007
    Posts
    14

    Question Re: Remove Duplicate Items in Listbox

    Well I extract links from a web page and some web pages have duplicated URLs. I cant find a way to check to see if the URL is in the listbox before adding?


  5. #5
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Remove Duplicate Items in Listbox

    You can check with findstringexact.
    Code:
    'if FindStringExact returns -1 then the item doesnt exist in the listbox
    
    If ListBox1.FindStringExact(yourstring) = -1 Then
                ListBox1.Items.Add(yourstring)
    End If
    Casey.

Posting Permissions

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



Click Here to Expand Forum to Full Width