我已经想通了。此解决方案允许您选择指定的索引开始搜索并检查索引为 1 的列。(通常是您的第二列)
Private Function FindLogic(ByVal LV As ListView, ByVal CIndex As Integer, ByVal SearchFor As String) As Integer
Dim idx As Integer
Dim It = From i In LV.Items Where i.index > CIndex And i.SubItems(1).Text = SearchFor
If It.Count > 0 Then
idx = It(0).Index
Else
idx = -1
End If
Return idx
End Function
您还可以在函数中添加另一个参数,以便您可以选择不同的列来检查字符串,如下所示:
Private Function FindLogic(ByVal LV As ListView, ByVal CIndex As Integer, ByVal Column As Integer, ByVal SearchFor As String) As Integer
Dim idx As Integer
Dim It = From i In LV.Items Where i.index > CIndex And i.SubItems(Column).Text = SearchFor
If It.Count > 0 Then
idx = It(0).Index
Else
idx = -1
End If
Return idx
End Function
要使用这个函数,它看起来像这样:
FindLogic(Listview1, 1, 1, "Dog")
你也可以让它从一个选定的项目中搜索,如下所示:
FindLogic(Listview1, 1, LV.SelectedIndices(0), "Dog")