gpt4 book ai didi

vb.net - 检查列表框是否包含文本框

转载 作者:行者123 更新时间:2023-12-04 04:39:51 26 4
gpt4 key购买 nike

我知道我可以使用 .FindString为此,但由于某种原因它不起作用。

基本上,如果列表框项目只包含文本框文本的一部分,它会执行操作。

这是无效代码的示例:

Dim x As Integer = -1
x = ListBox1.FindString(TextBox1.Text)
If x > -1 Then
'dont add
ListBox2.Items.Add("String found at " & x.ToString)
Else

End If

最佳答案

FindString方法返回以搜索字符串( MSDN )开头的第一项。如果要匹配整个项目,则必须使用 FindStringExact ( MSDN )。如果要执行更复杂的搜索,则必须遍历 ListBox 中的所有元素。 .

更新:
提供 OP 期望的确切功能的代码。

For i As Integer = 0 To ListBox1.Items.Count - 1
If (ListBox1.Items(i).ToString.Contains(TextBox1.Text)) Then
ListBox2.Items.Add("String found at " & (i + 1).ToString) 'Indexing is zero-based
Exit For
End If
Next

关于vb.net - 检查列表框是否包含文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19065468/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com