我正在开发一个项目,程序从表中获取项目并将其放在列表视图中。现在我想检查前3项与我设置的另一个列表视图中的项目是否匹配,并返回一条消息,无论listview1是否包含listview2中的任何项目。我可以为整个listview1做这个,但我想检查前三名。
For Each li As ListViewItem In ListView2.Items
Dim liToFind As ListViewItem = ListView1.FindItemWithText(li.Text)
If Not IsNothing(liToFind) Then
Using New Centered_MessageBox(Me)
MessageBox.Show(li.Text & " has released a new episode!", "New release", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Using
End If
Next
这是我到目前为止的代码,我正在检查listview2中的项目文本以查看它是否与listview1中的任何项目匹配,但是无法弄清楚如何使用前3个来执行此操作
帮助会很大的帮助!
答案 0 :(得分:0)
这是一个例子 - 显然你可以在这里更聪明。
Dim checkrows As Integer = 3
Dim numFound As Integer
For row As Integer = 0 To Math.Min(checkrows - 1, ListView1.Items.Count - 1)
Dim text As String = ListView1.Items(row).Text
Dim found As Boolean
For Each item2 As ListViewItem In ListView2.Items
If text.Contains(item2.Text) Then
found = True
Exit For
End If
Next
If found Then numFound += 1
Next
If numFound > 0 Then MessageBox.Show("At least one of the first " & checkrows.ToString & " rows in ListView1 matches a row in ListView2")
If numFound = checkrows Then MessageBox.Show("The first " & checkrows.ToString & " rows in ListView1 match a row in ListView2")
答案 1 :(得分:0)
这对我有用,感谢AltF4,但你的确没有为我做好准备。 Ty无论如何都要把时间花在这上面< 3
Dim checkrows As Integer = 3
Dim numFound As Integer
For row As Integer = 0 To Math.Min(checkrows - 1, ListView1.Items.Count - 1)
Dim text As String = ListView1.Items(row).Text
Dim found As Boolean
For Each item2 As ListViewItem In ListView2.Items
If text.Contains(item2.Text) Then
found = True
Exit For
End If
Next
If found Then numFound += 1
Next
If numFound > 0 Then MessageBox.Show("At least one of the first " & checkrows.ToString & " rows in ListView1 matches a row in ListView2")
If numFound = checkrows Then MessageBox.Show("The first " & checkrows.ToString & " rows in ListView1 match a row in ListView2")