i have a listview with subitems namely NAME Age and Position. The positions are Driver, Conductor and Inspector. I have 3 textbox namely CountD, CountC, CountI. What i want is if i Click the Name in the listview where the position is driver, the CountD.text will display 1 and if i Click another name in the listview where the position is also driver, the CountD.text will display 2 and so on. Also in other two texboxes where there position is Conductor and Inspector. HELP ME PLEASE GODBLESS

You will want to match things up.

Declare a class wide variable to reference the clicked item.

Example:

Private lviCurrent As New ListViewItem

Next you will want to set the item to the selected item (in the listview's click event)

If IsNothing(ListView1.SelectedItems) = false Then
    For each lvi As ListViewItem in ListView1.SelectedItems
        lviCurrent = lvi
    Next
End If

Now, to pull the values into the text box, do the following:

With lviCurrent
    txtName.Text = .Text 'This will be the first column
    txtAge.Text = .SubItems(0).Text 'This will be the second column
    txtPosition.Text = .SubItems(1).Text 'This will be the third column
End With

oh sir thank you for the code i will try it later

im sorry sir im a newbie in vb.net what do you mean by "Declare a class wide variable to reference the clicked item".

In the (form I am asuming) class that the listview belongs in.

Example:

Public Class Form1
    Private lviCurrent As New ListViewItem

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles Me.Load

    End Sub
End Class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.