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.
Printable View
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.
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?
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
Can you post what you found?
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
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