-3

我有 4 个文本框用于填充 ListView。我需要第 4 个文本框来验证数据是否不在列表中。

4

2 回答 2

0

您需要遍历列表并验证每个单元格。我不确定你是如何提交你的项目的,但我会假设它是在一个Button_Click事件中。

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    'I'll store "abc" in TextBox4.Text for my example
    TextBox4.Text = "abc"

    'First we loop through each listview item (or row)
    For Each item As ListViewItem In ListView1.Items
        'For each item, we will loop through it's subitems
        For Each subItem As ListViewItem.ListViewSubItem In item.SubItems
            'If textbox4.text is equal to the current subitem, we've found that the item already exists
            If Textbox4.Text = subItem.Text Then
                MsgBox("Item abc is already in the list")
            End If
        Next
    Next
End Sub
于 2013-05-29T18:28:37.517 回答
0

您也可以使用 Find 方法,ListView1.Items.Find("myString", True). 这将搜索每个项目及其所有子项目。

与其直接调用按钮单击处理程序,不如使用特定按钮的 PerformClick 方法。

于 2013-05-29T19:40:00.923 回答