问题描述
我一直在想怎么做 1;搜索我需要获得匹配项和 2 的项目;如果它还没有结束,让它能够为我提供下一个搜索匹配。而这段代码不能做那些(注意:这段代码在搜索按钮中)
我一直在想如何做到这一点,因为我已经尝试了好几天了,我的老师并没有真正给我们太多,她只是告诉我们按照我输入的内容做段落(和 atm 我们都在挣扎,哈哈)
顺便说一下,我需要立即答复!
Dim searchText = Me.TextBox4.Text
If searchText = String.Empty Then
'Don't bother searching if there's no text to search for.
MessageBox.Show("Please enter search text.")
Else
Dim startIndex = 0
Dim item As ListViewItem = nothing
'If one item is selected and it already matches the search text,''start searching from the next item.
'Otherwise,start searching from the beginning.
If Me.ListView1.SelectedItems.Count = 1 AndAlso Me.ListView1.SelectedItems(0).Text = searchText Then
startIndex = Me.ListView1.Selectedindices(0) + 1
End If
'Don't search if we're already at the end of the items.
If startIndex < Me.ListView1.Items.Count Then
Do
'Find the first partial match.
item = Me.ListView1.FindItemWithText(searchText,False,startIndex)
If item Is nothing OrElse item.Text = searchText Then
'There is no partial match or we have already found a full match.
Exit Do
End If
'Search again from the item after the last partial match.
startIndex = item.Index + 1
'Stop searching if we're at the end of the items.
If startIndex >= Me.ListView1.Items.Count Then
Exit Do
End If
Loop
End If
'Clear the current selection.
Me.ListView1.SelectedItems.Clear()
If item Is nothing Then
MessageBox.Show("No match found.")
Else
'Select the matching item.
item.Selected = True
item.EnsureVisible()
Me.ListView1.Select()
End If
End If
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)