Is there any way to cast listView.SelectedIndices
to List<int>
?
I tried this
(List<int>)reListViewAllMovies.SelectedIndices.Cast<List<int>>()
But it doesn't work (InvalidCastException).
If solution doesn't exist, is there any "one-line" solution for example using lambda expression?
Old question but I was looking for a solution myself. .NET v4.5. I don't know about earlier versions of the framework.
var list = myListView.SelectedIndices.Cast<int>().ToList();
reListViewAllMovies.SelectedIndices.Select(i => (int)i).ToList();
Or, you could use a foreach
loop to convert the results:
var newList = new List<int>();
foreach(int i in reListViewAllMovies.SelectedIndices)
{
newList.Add(i);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With