tags:

views:

96

answers:

2

I'm trying to get the value of each selected item in a list view. Problem is that when I use Intellitext to find out what I can get out of "Item", my options are:

Equals
GetHashCode
GetType
ToString

When I use ToString, I get the following:

{Text = "ItemLabel"}

When all I want is:

ItemLabel

foreach(var Item in ListView.SelectedItems)
{
Item.ToString(); //{Text = "ItemLabel"}
}

How can I make it so that I can get the text that I want (without parsing the results from ToString).

+1  A: 

Hum. If ListView.SelectedItems is an IEnumerable (and not an IEnumerable<T>), then var will infer the elements of the sequence as an Object. Specify the correct type instead.

Etienne de Martel
+3  A: 

Use ListViewItem instead of var:

foreach(ListViewItem Item in ListView.SelectedItems)
{
    Item.Text; // "ItemLabel"
}
Tim Robinson
Spectacular, thanks!
Soo