Dear Friends,

I am new to vb.net. I would like to know how can I get the listview selected values in respective textboxes? Could somebody will help me with the code, please?

Using Visual Studio 2008
MS Access Database 2007

txtSearch

Thanks.

Hi,

You can try something like this:

TextBox1.Text = ListView1.SelectedItems(0).ToString

Hi,

You can try something like this:

TextBox1.Text = ListView1.SelectedItems(0).ToString

Thanks for the reply. I tried like the following:

Private Sub txtFill_Click()
        txtTAID.Text = LVW.SelectedItems(0).ToString
        txtVNO.Text = LVW.SelectedItems(1).ToString
        txtVNM.Text = LVW.SelectedItems(2).ToString
    End Sub

And I called it in the following listview click event:

Private Sub txtFill_Click()
        txtTAID.Text = LVW.SelectedItems(0).ToString
        txtVNO.Text = LVW.SelectedItems(1).ToString
        txtVNM.Text = LVW.SelectedItems(2).ToString
    End Sub
End Class

Getting error on code line:

txtVNO.Text = LVW.SelectedItems(1).ToString

I tried and removed the next two lines keeping first line as it is. Though it did not show any error, it did not show the listview rows value in textboxes.

Please do any further help.

Edited 6 Years Ago by Learner7: n/a

Sorry for the wrong code mention in the ListView Click Event (LVW_Click).

The following is the code which I have actually written:

For Sub:

Private Sub txtFill_Click()
txtTAID.Text = LVW.SelectedItems(0).ToString
txtVNO.Text = LVW.SelectedItems(1).ToString
txtVNM.Text = LVW.SelectedItems(2).ToString
End Sub

And for the ListView Click Event:

Private Sub LVW_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LVW.Click
Call Fill_TextBox()
End Sub

Please do help. Many thanks.

Edited 6 Years Ago by Learner7: n/a

Attachments Error.JPG 55.57 KB

For ListView you should not use SelectedItems in this manner.
SelectedItems is a collection of selected items (rows) in the ListView.
So, if there's only 1 row selected then SelectedItems only contain 1 item. Therefore LVW.SelectedItems(1) will result in error.

If you wish to retrieve values from the subsequent columns of the row that is selected you can use the SubItems property.

Private Sub txtFill_Click()
txtTAID.Text = LVW.SelectedItems(0).Text
txtVNO.Text = LVW.SelectedItems(0).SubItems(0).Text
txtVNM.Text = LVW.SelectedItems(0).SubItems(1).Text
End Sub

For ListView you should not use SelectedItems in this manner.
SelectedItems is a collection of selected items (rows) in the ListView.
So, if there's only 1 row selected then SelectedItems only contain 1 item. Therefore LVW.SelectedItems(1) will result in error.

If you wish to retrieve values from the subsequent columns of the row that is selected you can use the SubItems property.

Private Sub txtFill_Click()
txtTAID.Text = LVW.SelectedItems(0).Text
txtVNO.Text = LVW.SelectedItems(0).SubItems(0).Text
txtVNM.Text = LVW.SelectedItems(0).SubItems(1).Text
End Sub

Fantistic. Thanks a lot for the help. It works quite fine. But how can I rate this thread?

Regards.

Edited 6 Years Ago by Learner7: n/a

This question has already been answered. Start a new discussion instead.