Results 1 to 6 of 6

Thread: Duplicates in a ListBox

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Duplicates in a ListBox

    What's the easiest way to find duplicates in a ListBox and remove them?

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Duplicates in a ListBox

    I think it will be better to find the diplicated before you enter them in the ListBox.
    Where does the ListBox data come from ?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: Duplicates in a ListBox

    My program adds items to the listbox from a file that the user can edit.

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

    Re: Duplicates in a ListBox

    the fastest way to check before you add is the use of sendmessage
    VB Code:
    1. Option Explicit
    2. Private Declare Function SendMessageString Lib "user32" Alias "SendMessageA" _
    3. (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
    4. Const LB_FINDSTRINGEXACT = &H1A2
    5.  
    6. '------------------------------------------------------
    7. 'then part of the sub adding the strings
    8.  
    9. If SendMessageString(List1.hwnd, LB_FINDSTRINGEXACT, -1, ByVal The_string_to_add) = -1 Then
    10.  List1.AddItem The_string_to_add
    11. End If

    casey.

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Duplicates in a ListBox

    ...bearing in mind that the search isn't case sensitive

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    400

    Re: Duplicates in a ListBox

    That's okay all the items are all automatically converted to upper case anyway. Thanks!

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