Linq to SQL DataGrid筛选器 [英] Linq to SQL DataGrid Filter

查看:88
本文介绍了Linq to SQL DataGrid筛选器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ICollectionView将Linq筛选为SQL查询结果,但是我一直收到错误消息,该方法不受支持.有人可以查看下面的代码,然后告诉我为什么无法过滤视图吗?

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?

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"));

推荐答案

只是一个猜测,因为我无法用您提供的任何东西来运行代码,但是您是否尝试过以下操作:

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:

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"));



可能是使用ItemsSource作为参数导致了您的问题.



It may be that using the ItemsSource as the argument is causing you the problems.


这篇关于Linq to SQL DataGrid筛选器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆