0

I have a usercontrol, with one list box and one list view control in it. For Listview i have bound the observablecollection of type TrafficManager class as shown below:

   private static ObservableCollection<TrafficManager> _trafficCollection;
            public ObservableCollection<TrafficManager> TrafficCollection
            {
                get { return _trafficCollection; }
                set
                {
                    _trafficCollection = value;
                    OnPropertyChanged("TrafficCollection"); 
                }
            } 

I have bound this to itemsource of list view. Now my requirement is on selection of the listbox item, i need to filter some items of the listview. For that i used a linq to get the desired rows from list view and added that to the list view collection. Before adding i did a listview Collection TrafficCollection.Clear() and then added to that collection.But now the issue is on selection of another item in list box i need the original listview contents again to carry out the filtering using the linq again. Here once the TrafficCollection.Clear() executes the original observable collection data vanishes. How do i maintain a backup of original observable collection data "TrafficCollection" of listview. Remember i have only one view. Is there anyway to do this? Please let me know.

Ataur Rahman Munna
  • 3,887
  • 1
  • 23
  • 34
ImHere
  • 15
  • 5
  • http://stackoverflow.com/questions/14497506/collectionviewsource-how-to-filter-data – WPFUser Dec 19 '16 at 12:15
  • You hold onto the original items instead of throwing them away. Your VM can have more than one collection holding references to the same items. –  Dec 19 '16 at 15:15
  • Thank you, but can you let me know how to hold references to same class items. If I modify the items through add or remove won't the reference collection also get modified? – ImHere Dec 20 '16 at 04:54

1 Answers1

0

you can use CollectionViewSource filtering, refer here

SO Link: Trigger Filter on CollectionViewSource

this will not clear original collection.

Community
  • 1
  • 1
WPFUser
  • 1,145
  • 7
  • 24