Results 1 to 6 of 6

Thread: remove duplicates from a combo box

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    14

    remove duplicates from a combo box

    Hi, can anyone tell me how you can remove duplicate items from a combo box, iv already searched the forum and theres explanations for removing dups from only listboxes, does any one have any ideas, im using vb.net.

  2. #2
    New Member
    Join Date
    Apr 2004
    Posts
    12

    more info

    How or rather from where is your combobox's items being populated? If you are pulling from a db then try a Select Distinct statement, if that isn't the case then can you maybe elaborate a bit more on the problem?

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    14
    the items are from a file that is put into an array and then placed into the combo box. Iv been looking at the list box code but i cant change it to work with a combo box, could this be because im using vb.net and some of the commands are for vb5/6

  4. #4
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171
    Can you post what you found?


    Has someone helped you? Then you can Rate their helpful post.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    14
    this is the code for the listbox
    ---------------------------------------------------------------------
    Dim i As Long
    Dim j As Long
    With List1
    For i = 0 To .ListCount - 1
    For j = .ListCount To (i + 1) Step -1
    If .List(j) = .List(i) Then
    .RemoveItem j
    End If
    Next
    Next
    End With

    End Sub


    ---------------------------------------------------------------------
    this is the best i can alter the code
    ---------------------------------------------------------------------

    Dim i As Long
    Dim j As Long
    With cboIUpREF
    For i = 0 To .Items.Count - 1
    For j = .Items.Count To (i + 1) Step -1
    If .Items.Item(j) = .Items.Item(i) Then
    .Items.Remove(j)
    End If
    Next
    Next
    End With
    ---------------------------------------------------------------------

    when this is error apears
    -----------------------------------
    An unhandled exception of type 'System.ArgumentOutOfRangeException' occurred in system.windows.forms.dll

    Additional information: Specified argument was out of the range of valid values.
    -------------------------------------
    can any one tell me if the code that i have changed should work, if not can you try to get it to work

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    14
    the line
    If .Items.Item(j) = .Items.Item(i) Then
    seems to be the cause of the error, what command could i use instead of .items.item

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