|
-
Apr 10th, 2004, 12:28 PM
#1
Thread Starter
New Member
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.
-
Apr 10th, 2004, 01:45 PM
#2
New Member
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?
-
Apr 10th, 2004, 03:49 PM
#3
Thread Starter
New Member
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
-
Apr 10th, 2004, 04:07 PM
#4
-
Apr 10th, 2004, 04:07 PM
#5
Thread Starter
New Member
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
-
Apr 10th, 2004, 04:20 PM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|