Reputation: 17
I want to remove item from Combobox after using it in Listview
I fill combobox in Form_load with:
With CmbCode
.items.clear
For N 1 to 9999
.items.add(N)
Next
End With
Here I need Something to remove the Used numbers From Combobox (CmbCode) I use a library Class To fill the listview:
Dim Formatter As New BinaryFormatter
Dim AL As New ArrayList
ReadFile.Seek(0, SeekOrigin.Begin)
AL=CType(Formatter.Deserialize(ReadFile), ArrayList)
Dim itm As Object
For Each itm In AL
Lsv1.Itmes.Add(itm)
Next
ReadFile.Close
Formatter = Nothing
I have no idea how to remove the used numbers (In Listview) from the combobox. Any Idea how to approach the problem.
Upvotes: 0
Views: 151
Reputation: 54427
Don't use that loop when loading. Call Items.AddRange
to add all the items in one go. If you keep the items that you have previously removed in a list then you can easily exclude those when loading, e.g.
Dim items = Enumerable.Range(1, 9999).Except(previouslyRemovedItems).ToArray()
CmbCode.Items.AddRange(items)
I haven't tested that and it might be that AddRange
will not accept a value-type array, so you may need to cast as type Object
, i.e.
Dim items = Enumerable.Range(1, 9999).Except(previouslyRemovedItems).Cast(Of Object)().ToArray()
Upvotes: 1