Failed_Noob
Failed_Noob

Reputation: 1357

How to get the selected row items in ListView

This is my ListView, Column 1 for ID and Column 2 for Notes

enter image description here

I have a Multi-Line textbox and a Button Like this

enter image description here

I want to load the selected note on the textbox when the button is clicked. How can I do this ?

Upvotes: 0

Views: 46715

Answers (2)

Bala R
Bala R

Reputation: 108937

You can try something similar to this (you'll have to tweak it for your setup)

If listView.SelectedItems.Count > 0 Then
    textBox.Text = listView.SelectedItems(0).SubItems(1).Text
End If

if you don't like the idea of using column index and if you have your columns setup right then you should be able to do .SubItems("ID").Text

Upvotes: 5

user274481
user274481

Reputation: 11

the following may work

For Each item As ListViewItem In ListView1.SelectedItems()
        TextBox1.AppendText(item.Text & ":" & item.SubItems(1).Text & Environment.NewLine)
Next

Upvotes: 0

Related Questions