How to access Item text using: foreach(var Item in ListView.SelectedItems){}
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<br/>
GetHashCode<br/>
GetType<br/>
ToString
When I use T开发者_开发技巧oString, 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).
Use ListViewItem
instead of var
:
foreach(ListViewItem Item in ListView.SelectedItems)
{
Item.Text; // "ItemLabel"
}
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.
精彩评论