0

I create a public CollectionView (cvs) and bind that to my ListView Control in a WPF application. Then there are a series of filters that add in delegates to filter my cvs object. Everything works fine in this aspect of the program.

public ICollectionView cvs { get; set; }
public ObservableCollection<T> TLIST
...
cvs = CollectionViewSource.GetDefaultView(TLIST);
ListViewName.ItemsSource = cvs;
...
//Filters created 
cvs.Filter = groupFilter.Filter;

What I'm trying to do is create Excel files of the items in my list. I can send the entire collection (TLIST) to an OpenXML function and create my files just fine. Where I'm struggling is I want to only send the filtered items into the function and figure I need to somehow send the filtered cvs.

In short, what I'm trying to get is --> cvs.ToList() but this is not a valid operation. and getting the error

"Unable to cast object of type 'System.Windows.Data.ListCollectionView' to type 'System.Collections.Generic.List`1"

Anything glaringly obvious that I'm doing wrong? Any guidance is appreciated.

Note: Even when I inspect cvs it shows all the items not just the filtered ones.

markokstate
  • 923
  • 2
  • 14
  • 28
  • I understand I could probably just filter my TLIST with the same criteria but was hoping there was a smarter way to utilize my already filtered collection. – markokstate Apr 16 '15 at 18:16
  • Looks like you are trying to store a ListCollectionView into a variable (or pass as a parameter) that is defined as List and you didn't include that code. If the next line was `var something=cvs.ToList();` I would expect that line to work just fine. – Robert McKee Apr 16 '15 at 18:19
  • I am trying to convert cvs.ToList() via "var list = (List)cvs.ToList();" – markokstate Apr 16 '15 at 18:26

1 Answers1

0

You can try the below which gives filtered list.

List<MyObject> lst = cvs.Cast<MyObject>().ToList();
Ayyappan Subramanian
  • 5,348
  • 1
  • 22
  • 44