k80sg
k80sg

Reputation: 2473

Removing items from ListBox A based on the items in ListBox B

I am trying to remove items from a listbox based on the items on another listbox, this seems simple but apparently I can't get my code to work, please advice. Thanks.

   Dim listRemove As New List(Of ListItem)
    For Each item As ListItem In QualOutletToBox.Items
        listRemove.Add(item)                  ' Collect items from ListBox A
    Next
    For Each item In listRemove
        QualOutletFromBox.Items.Remove(item)  ' Remove items from ListBox B based on ListBox A
    Next

Upvotes: 0

Views: 357

Answers (1)

competent_tech
competent_tech

Reputation: 44931

Regarding the follow-on question, yes, there is a much less resource intensive method, a single loop:

For Each item As ListItem In QualOutletToBox.Items
    QualOutletFromBox.Items.Remove(item)  ' Remove items from ListBox B based on ListBox A
Next

Upvotes: 3

Related Questions