DataGridView过滤
我正在创建一个应该能够获取任何类型列表的控件。本质上是以下代码:
void BindData(IList list)
{
BindingSource bs = new BindindSource();
bs.DataSource = list;
this.DataGridView.DataSource = bs;
}
现在我有一个文本框,我想用它来过滤网格中的数据。我认为这就像设置 bs.Filter 属性一样简单,但显然不是。 bs.SupportsFiltering 也返回 false。
这是我使用 IList 的问题吗?如果是这样,是否有另一个集合类/接口可以用来达到相同的效果? (同样,我不确定列表中对象的类型是什么。
I'm creating a control that should be able to take any kind of list. Essentially the following code:
void BindData(IList list)
{
BindingSource bs = new BindindSource();
bs.DataSource = list;
this.DataGridView.DataSource = bs;
}
Now I have a textbox that I want to use to filter the data in my grid. I figured it'd be as simple as setting the bs.Filter property but apparently not. The bs.SupportsFiltering returns false as well.
Is this an issue with me using the IList? If so, is there another collection class / interface that I can use to achieve the same effect? (Again, I'm not sure what the type is of the objects in the list.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于不知道我要传递的类型,我导致手动过滤数据。
这是我的代码片段。效果很好。希望对于大量数据来说它不会太慢。 :: 手指交叉 ::
Not knowing the type I'm getting passed, I resulted in filtering the data by hand.
Here's my code snippet. It works well. Hopefully it doesn't prove to be too slow with larger amounts of data. :: Fingers Crossed ::
IBindingListView 接口通过添加对列表过滤的支持来补充 IBindingList 接口的数据绑定功能。
可以在此处找到一些通用 IBindingListView 实现的解决方案。
The IBindingListView interface supplements the data-binding capabilities of the IBindingList interface by adding support for filtering of the list.
A couple of solutions for generic IBindingListView implementations can be found here.