Visual Basic:从列表框中筛选项目
问题描述:
我正在尝试一些看起来很简单的事情,但现在我一直在解决这个问题。 我想要做的是当按下按钮'Filter'时,从列表框中删除包含字符串“Item”的所有项目。Visual Basic:从列表框中筛选项目
这是我当前的代码:
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
截图:
答
万一有人有类似的问题,我用颠倒循环能够解决这个问题:
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