Hi All..
I want to get selected item on listview.
Does any one know how to solve this???
I'm using vb.net 2003

For Top Level:

MsgBox(ListView1.SelectedItems(0).Text)

And Subitems:

MsgBox(ListView1.SelectedItems(0).SubItems(1).Text)

You may want to make sure you have subitems before trying that one ;)

dim x as integer
dim y as integer
dim str as string

private sub ON_BUTTON_CLICK(...sender as OBJECT,... e as MOUSE_EVENT_ARGS)
    x = e.X
    y = e.Y
    str = ListView1.GetItemAt(x, y).Text
end sub

Hi All..
I want to get selected item on listview.
Does any one know how to solve this???
I'm using vb.net 2003

Dunno if this will help - I'm using vb 2008 express
Textbox1.Text = Listview1.Items.Item(Listview1.FocusedItem.Index).SubItems(x).Text

-- where x is the subitem value you want to retrieve

bradleystephens
>>well FocusedItem not available on vb 2003.

Cikara21
>> i'll try your code. Thx

Comatose
>> thx for the codes. I want if i selected any row i can get item on it.
so, how i can know the sub item of selected item.
MsgBox(ListView1.SelectedItems(0).SubItems(This part i wanted).Text)

Please help...Thx

On Form Load,I m adding items to the ListView.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim f As System.Drawing.Font = New System.Drawing.Font("Arial", 12.0!, System.Drawing.FontStyle.Bold)
        Dim lvitem As ListViewItem
        lvitem = ListView2.Items.Add("1")
        lvitem.SubItems.Add("A", Color.Black, Color.White, f)
        lvitem.SubItems(1).Font = f
        lvitem.UseItemStyleForSubItems = False
        lvitem = ListView2.Items.Add("2")
        lvitem.SubItems.Add("B", Color.Black, Color.White, f)
        lvitem.SubItems(1).Font = f
        lvitem.UseItemStyleForSubItems = False
           End Sub

On Listview Click,I show the text of second Subitem as message.

Private Sub ListView2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView2.Click
        Dim lCount As Integer
        For lCount = 0 To ListView2.Items.Count - 1
            If ListView2.Items(lCount).Selected = True Then
                MsgBox(ListView2.Items(lCount).SubItems(1).Text)
                Exit For
            End If
        Next
End sub

Hi All..
I want to get selected item on listview.
Does any one know how to solve this???
I'm using vb.net 2003

On Error Resume Next
TextBox1.Text = lv1.SelectedItems(0).SubItems(0).Text

here lv1 is name of Listview..

Above coding should be written inside lv1's selected Index changed event..

This coding is used to store listitem value in textbox..similar u can store it inwhich u want to get..........

Hi dnk,
I have some problem with this thread. Did you have found the answer?

Thank you.

No, its not solved. I already know how to get it.
There are no problem in the first time click but error came up when next click.

Try This :

Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
Dim i As Integer
If ListView1.SelectedItems.Count = 0 Then Exit Sub 
i = Val(ListView1.SelectedIndices.Item(0).ToString)
MsgBox(ListView1.Items(i).SubItems(1).Text)
End Sub

You also can use this line of code to get selected index :

i = Val(ListView1.SelectedItems(0).Index)
'and this
i = ListView1.SelectedIndices(0)
Comments
Your helping make this thread solved after 2 years :D

Wow,,finally this thread can be solved.
Thanks Jx,
I already do like your code use SelectedIndices, but it just working in first click but not the next click. But you solved it now.
Thanks to sharing sir.

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