【问题标题】:Removing items from ListBox A based on the items in ListBox B根据 ListBox B 中的项目从 ListBox A 中删除项目
【发布时间】:2011-11-06 03:38:29
【问题描述】:

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

   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

【问题讨论】:

  • 好的,显然我在填充 ListBox B 之前放置了那部分代码。一个问题,因为这已经发布了,有没有一种资源效率更高的方法来做到这一点?谢谢。

标签: vb.net


【解决方案1】:

关于后续问题,是的,有一个资源密集型方法要少得多,即单个循环:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多