Reputation: 199
I have a ListCollectionView that I would like to put into a List, but I'm unsure how to do this.
Below is the code that I have tried. It returns an error that ListCollectionView
does not contain a definition for ToList().
var repItems = (ListCollectionView)view;
var listItems = repItems.ToList();
Can anyone show me how?
Upvotes: 2
Views: 2474
Reputation: 1253
ListCollectionView implements non-generic IEnumerable so you can't call generic ToList extension method on it. You need to cast it first:
var repItems = (ListCollectionView)view;
listItems = repItems.Cast<object>().ToList();
Upvotes: 2
Reputation: 743
You can do like this.Instead of using List use IList
var repItems = (ListCollectionView)view;
IList<object> list = repItems.SourceCollection as IList<object>;
Upvotes: 0