I have tried this code (which works for anything that implements IEnumerable, but apparently not a selectedListViewItemCollection)
foreach (ListViewItem item in ((IEnumerable<ListViewItem>)categoryListView.SelectedItems).AsEnumerable().Reverse())
{
// do something
}
I get an InvalidCastException when this is run.
That's because SelectedItems
does not implement generic IEnumerable<ListViewItem>
.
Use Cast<T>
method instead:
foreach (ListViewItem item in categoryListView.SelectedItems.Cast<ListViewItem>().AsEnumerable().Reverse())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.