I want to create a ListCollectionView with a generic IList<T> but the constructor gets a non-generic IList.
How can I convert my list from IList<T> to IList?
if there is another way to create a ListCollectionView with a generic IList<T> I would like to hear it :)
Annoyingly, IList<T> is one of those interfaces which doesn't implement its non-generic counterpart IList.
If you can find a way to pass a List<T> rather than an IList<T> (or some other type which implements IList as well as IList<T>, such as ObservableCollection<T>), that's going to be easiest. This might mean changing your application so that you pass a List<T> or something else around rather than an IList<T>.
Otherwise, you might have to create a new List<T> using the elements in the IList<T>, and pass that (i.e. myList.ToList()). Note that this means that you've created a copy of your list, and so changes to the original won't be reflected in the copy. In particular, ListCollectionView checks to see whether the source collection implements INotifyCollectionChanged, and subscribes to collection changed events if so: this obviously won't work if you create a copy of your list.
List<T> implements IList (IList<T> does not). Create a List<T> from your IList<T> and pass that to the ListCollectionView constructor:
ListCollectionView lcv = new ListCollectionView(new List<YourType>(yourIList));
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