VB.NET Filtering ListItems Problem

后端 未结 5 696
北荒
北荒 2021-01-25 11:15

I am trying to filter a ListBox based on the presence of a string. Basically, if there is a ListItem that doesn\'t contain the string then I want to remove all ListItems that do

5条回答
  •  春和景丽
    2021-01-25 11:48

    Based on balpha's help above, this is what I ultimately did:

    Dim StringPresent As Boolean = False
    Dim Item As ListItem
    
    For Each Item In CtheList.Items
        If Item.Text.IndexOf("W:") = -1 Then
            StringPresent = True
            Exit For
        End If
    Next
    
    If StringPresent = True Then
        Dim i As Integer
        For i = CtheList.Items.Count - 1 To 0 Step -1
            If CtheList.Items.Item(i).Text.IndexOf("W:") > -1 Then
                CtheList.Items.RemoveAt(i)
            End If
        Next i
    End If
    

提交回复
热议问题