FindItemWithText获取listview vb.net中的字符串

时间:2014-02-14 04:35:39

标签: vb.net listview

我有一个有效的代码。但问题很少。我不知道为什么它没有将listview中的文本作为字符串。

这是我的代码有问题:

Private Sub ListView2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView2.SelectedIndexChanged

    Dim ChkContact As New ListViewItem

    ChkContact = lvContact.FindItemWithText(listview2.FocusedItem.Subitem(1).text)

    If ChkContact IsNot Nothing Then
        txtContact.Text = ChkContact.SubItems(1).Text
        ListView2.FocusedItem.SubItems(0).Text = ChkContact.SubItems(1).Text

    Else
        txtContact.Text = "no match found"
        ListView2.FocusedItem.SubItems(0).Text = "Not in the list"
    End If

End Sub

如果我更改此代码

ChkContact = lvContact.FindItemWithText(listview2.FocusedItem.Subitem(1).text)

到这个

ChkContact = lvContact.FindItemWithText("1234") 'with this it is working

谢谢......

0 个答案:

没有答案