根据ListBox B中的项目从ListBox A中删除项目

时间:2011-11-05 17:32:52

标签: vb.net

我正在尝试根据另一个列表框中的项目从列表框中删除项目,这看起来很简单,但显然我无法让我的代码工作,请咨询。感谢。

   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

1 个答案:

答案 0 :(得分:3)

关于后续问题,是的,资源密集程度要低得多,单个循环:

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