renge
renge

Reputation: 27

FindItemWithText in listview and show the result in textbox vb.net

I have two listviews (lvMessage and lvContact) and one textbox.

lvMessage columns are Number, DateAndTime, and Message. lvContact columns are ID, Name, and ContactNumber

I am trying to find the match of lvMessage.subitem(Number) in lvContact.subitem(ContactNumber) and if an item is found, then the textbox should display lvContact.subitem(Name) - from the row matched.

Private Sub ListView2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.Click
    Dim ChkContact As New ListViewItem
    ChkContact = lvContact.FindItemWithText("12344")
    If ChkContact IsNot Nothing Then
        txtContact.Text = lvContact.Items(0).SubItems(1).Text 'i have problem with this line
    Else
        txtContact.Text = "no match found"
    End If

End Sub

This code is working in finding the text. but the result is always the same when it find the text from lvContact.

For example: if the "1234" is found txtContact.text = (subitem(2) from the row matched)

Upvotes: 1

Views: 1060

Answers (1)

Sathish
Sathish

Reputation: 4487

Change this

 txtContact.Text = lvContact.Items(0).SubItems(1).Text 

To

txtContact.Text = ChkContact .SubItems(1).Text 

Upvotes: 1

Related Questions