Convert ICollectionView to List<T>

user572844 picture user572844 · Jul 28, 2011 · Viewed 16.5k times · Source

I am binding property type of ICollectionView on DataGrid controls in WPF, .NET 4.0.

I use Filter on ICollectionView.

    public ICollectionView CallsView
    {
        get
        {
            return _callsView;
        }
        set
        {
            _callsView = value;
            NotifyOfPropertyChange(() => CallsView);
        }
    }

    private void FilterCalls()
    {
        if (CallsView != null)
        {
            CallsView.Filter = new Predicate<object>(FilterOut);
            CallsView.Refresh();
        }
    }

    private bool FilterOut(object item)
    {
       //..
    }

Init ICollection view:

IList<Call> source;
CallsView = CollectionViewSource.GetDefaultView(source);

I am trying to solve this problem:

For example source data count is 1000 items. I use filter, in DataGrid control I show only 200 items.

I would like convert ICollection current view to IList<Call>

Answer

Niloo picture Niloo · Jan 8, 2014

You can try:

List<Call> CallsList = CallsView.Cast<Call>().ToList();