如何检查Listbox选定项目中是否有特定单词?

4

我尝试过:

  1. 如果 ListBox1.Items 包含 "myword" Then
  2. 如果 ListBox1.SelectedIndex = ListBox1.Items.IndexOf("myword") Then
  3. 如果 ListBox1.SelectedItems.Item("myword") Then

但没有效果。

1个回答

2
尝试像这样做,listbox.items 属性是一个 ListBox.ObjectCollection
For Each i As Object In ListBox1.SelectedItems
    If CStr(i).Contains("myword") Then
        BackColor = Color.Blue ' Do your logic here, I just used setting the BackColor for a test
    End If
Next

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接