我有ListView两列,在列表视图中输入新项目之前,我想防止输入重复值,所以我找到ListView.FindItemWithText了实现这一点。
但我意识到,如果我输入232323,然后输入2323,这是不同的但以与第一个条目相同的数字开头,该函数返回该项目作为匹配项。
我想知道是否有任何方法可以匹配整个文本(精确文本)以避免上述情况。
这是我的代码:
Dim ChkSIM As New ListViewItem
ChkSIM = lvItems.FindItemWithText("2323")
If Not ChkSIM Is Nothing Then
lblErrorSIM.Text = "Already in list"
End If
Run Code Online (Sandbox Code Playgroud)
ListView.FindItemWithText 有一个重载,只能找到完全匹配的:
Dim ChkSIM As ListViewItem = lvItems.FindItemWithText("2323", True, 0, False)
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅文档。