How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview? How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
Go Back  Xtreme Visual Basic Talk > > > How do you get value of a selected item in a listview?


Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2006, 02:54 PM
bonedoc bonedoc is offline
Junior Contributor
 
Join Date: Mar 2006
Posts: 376
Default How do you get value of a selected item in a listview?


I was usning a listbox, and then started using a listview. I could get the value of the item I was selecting in the listbox with:

Dim x as string
x=listbox1.selecteditem

But, a listview does not have "selectedItem", so I cannot fing a way to get the value from the item selected. There is a "SelectedItems" for the listview, but I get the error

Dim x as string
x=listview1.selecteditems

"Collection cannot be converted to string"

How can I get the value of an item in a listview with a click or index changed event?

Last edited by bonedoc; 06-11-2006 at 03:29 PM.
Reply With Quote
  #2  
Old 06-13-2006, 02:24 AM
Allen G's Avatar
Allen G Allen G is offline
Centurion
 
Join Date: Jul 2004
Location: Arlington, Texas
Posts: 189
Default

Quote:
Originally Posted by bonedoc
I was usning a listbox, and then started using a listview. I could get the value of the item I was selecting in the listbox with:

Dim x as string
x=listbox1.selecteditem

But, a listview does not have "selectedItem", so I cannot fing a way to get the value from the item selected. There is a "SelectedItems" for the listview, but I get the error

Dim x as string
x=listview1.selecteditems

"Collection cannot be converted to string"

How can I get the value of an item in a listview with a click or index changed event?
Code:
Public ReadOnly Property SelectedItems() As System.Windows.Forms.ListView.SelectedListViewItemCollection
     Member of: System.Windows.Forms.ListView
Summary:
Gets the items that are selected in the control.

Return Values:
A System.Windows.Forms.ListView.SelectedListViewItemCollection that contains the items that are selected in the control. If no items are currently selected, an empty System.Windows.Forms.ListView.SelectedListViewItemCollection is returned.
The error you recieved is valid, SelectedItems is a Collection and therefore you can't convert it to a String directly. Now there are 2 ways of getting the selected value(s).

First, do you want only the first selected value?
Code:
    Private Sub lvPlaylist_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvPlaylist.SelectedIndexChanged

        If Not lvPlaylist.SelectedItems.Count = 0 Then
            Debug.WriteLine(lvPlaylist.SelectedItems.Item(0).Text, "Selected")
        End If

    End Sub
Or you could do it this way, if multiple items are selected.
Code:
    Private Sub lvPlaylist_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvPlaylist.SelectedIndexChanged

        If Not lvPlaylist.SelectedItems.Count = 0 Then
            For Each item As ListViewItem In lvPlaylist.SelectedItems
                Debug.WriteLine(item.Text, "Selected")
            Next
        End If

    End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview? How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview? How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
 
How do you get value of a selected item in a listview?
How do you get value of a selected item in a listview?
 
-->