如何在Listview中的特定列中搜索?

时间:2014-03-26 14:58:55

标签: vb.net visual-studio listview textbox

我正在尝试调整我在论坛上找到的代码,到目前为止,我的小调整使代码适用于我的表单。但是,当我希望它搜索第1列和第2列(至少第1列)时,我只允许在列表视图中搜索第0列。有谁知道如何调整我的代码,以便我可以搜索第1列和/或第2列中的名称?甲

启动“Console”的行也有“预期表达式”问题。我该如何结束这个表达?

以下是我的代码:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    Dim itm As ListViewItem
    Dim i As Integer

    For i = 0 To InstitutionAddContactListView.Items.Count - 1
        itm = InstitutionAddContactListView.SelectedItems(i)
        Console.WriteLine(ContactFirstColumnHeader = {1} ContactLastColumnHeader = {2},itm.SubItems(1),itm.SubItems(2))
        InstitutionAddContactListView.Items(i).Selected = False
        InstitutionAddContactListView.Items(i).BackColor = Color.White
    Next

    With InstitutionAddContactListView
        itm = .FindItemWithText(TextBox1.Text, False, 0, True)


        If Not itm Is Nothing Then
            .Items.Item(itm.Index).BackColor = Color.Blue
            .Items.Item(itm.Index).EnsureVisible()
        Else
            MsgBox("No Record Found!")
            For i = 0 To InstitutionAddContactListView.Items.Count - 1
                InstitutionAddContactListView.Items(i).Selected = False
                InstitutionAddContactListView.Items(i).BackColor = Color.White
            Next
            .Items(0).EnsureVisible()
            .Items.Item(0).BackColor = Color.Blue
            TextBox1.SelectionStart = 0
            TextBox1.Focus()
        End If
    End With
    itm = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

使用InstitutionAddContactListView         itm = .FindItemWithText(TextBox1.Text,TRUE,0,True)