我已经想通了。该解决方案允许您选择指定索引开始从该搜索和检查与列和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")
我实际上是试图从指定的索引搜索并搜索第一个实例并返回它的索引。所以我可以在第5行开始搜索并返回指定单词的第一个实例索引。 – user1632018
无论如何,它看起来像你想出来的。关键是访问SubItems而不是ListViewItem的Text属性。 – Wooster11