【问题标题】:Visual Basic: Filter Items from a listboxVisual Basic:从列表框中筛选项目
【发布时间】:2016-01-20 18:44:00
【问题描述】:

我正在尝试一些看似简单的事情,但我已经为这个问题绞尽脑汁好几天了。 我想要做的就是在按下按钮 'Filter' 时,从列表框中删除所有包含字符串“Item”的项目。

这是我当前的代码:

    Dim index As Integer = 0
    Dim amountItems As Integer = LSBItems.Items.Count - 1

    For i As Integer = 0 To amountItems
    LSBItems.SelectedIndex = index
    Dim l_text As String = LSBItems.SelectedItem.ToString
    If l_text.Contains("Item") Then
        LSBItems.Items.Remove(LSBItems.SelectedItem)
    End If
    index = index + 1
    Next

截图:

【问题讨论】:

    标签: visual-studio listbox items


    【解决方案1】:

    以防万一有人遇到类似问题,我可以使用反向循环解决此问题:

    For i As Integer = LSBItems.Items.Count - 1 To 0 Step -1
        If LSBItems.Items(i).Contains("Item") Then
            LSBItems.Items.RemoveAt(i)
        End If
    Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-19
      • 2011-05-04
      • 2012-05-09
      • 1970-01-01
      相关资源
      最近更新 更多