Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am attempting to filter the Linq to SQL querry results using ICollectionView but I keep getting an error that the method is not supported. Can someone please review the code below and tell me why the view is not able to be filtered?

XML
viewDataContext dc_view = new viewDataContext();

            var view_query = from e_view in dc_view.user_views
                            select e_view;

            data_grid.ItemsSource = view_query;

            ICollectionView linq_view = CollectionViewSource.GetDefaultView(data_grid.ItemsSource);

            linq_view.Filter = new Predicate<object>((o) => ((user_view)o).name.StartsWith("Scott"));
Posted

1 solution

This is only a guess since I cannot run the code with what little you have provided, but have you tried the following:

viewDataContext dc_view = new viewDataContext();
var view_query = from e_view in dc_view.user_views select e_view;
data_grid.ItemsSource = view_query;
var linq_view = CollectionViewSource.GetDefaultView(view_query);
linq_view.Filter = new Predicate<object>((o) => ((user_view)o).name.StartsWith("Scott"));.


I run the following and it works:

XML
var tests = new[] { new test { Name = "a" }, new test { Name = "b" }, new test { Name = "ab" }, new test { Name = "bb" } };
ICollectionView linq_view = CollectionViewSource.GetDefaultView(tests);
linq_view.Filter = new Predicate<object>(o => ((test)o).Name.StartsWith("a"));


It may be that using the ItemsSource as the argument is causing you the problems.
 
Share this answer
 
Comments
Member 9488156 26-Oct-12 10:47am    
Thanks for the reply. I tried your suggestion and I still receive the same error. I believe your correct that it has something to do with using the ItemSource as the argument because the CanFilter property shows false. Is there another way to filter the results in my datagrid using a similar method?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900