一个很好的集合在C#绑定到一个DataGridView使用时 [英] A good collection to use when binding to a DataGridView in C#
问题描述
什么是最好的集合数据绑定列表在C#中的DataGridView时使用?我目前只使用一个泛型列表,但是当有添加或从列表中删除对象的数据网格不会更新。我看着使用的BindingList或的ObservableCollection,但不能决定这将是最好使用将更新并易于梳理/过滤器,而无需重新绑定到数据网格。我目前在windows窗体工作的.Net 3.5,计划不久将到WPF框架。
What would be the best collection to use when binding a list of data to a DataGridview in C#? I'm currently using just a Generic List but the data grid doesn't update when there is objects added or removed from the list. I've looked at using a BindingList or a ObservableCollection, but can't decide which would be best to use that would update and be easy to sort/filter without having to rebind to the data grid. I'm currently working in windows form on .Net 3.5 framework with plans to move over to WPF soon.
推荐答案
-
的ObservableCollection< T>
将不为其工作,DataGridView的
:它实现INotifyCollectionChanged
,而不是IBindingList的
和DataGridView的
不知道INotifyCollectionChanged
。其目的是为WPF的绑定和Windows窗体 - 不使用
的BindingList< T>
是一个不错的选择,但要注意它不支持排序或筛选开箱。但是,你可以找到这些功能的一些自定义实现在网络上。 -
数据表
可能是你最好的选择,如果你需要整理和/或过滤能力
ObservableCollection<T>
won't work for aDataGridView
: it implementsINotifyCollectionChanged
, notIBindingList
, and theDataGridView
doesn't know aboutINotifyCollectionChanged
. It is intended for WPF bindings and is not used in Windows FormsBindingList<T>
is a good option, but note that it doesn't support sorting or filtering out of the box. However, you can find some custom implementations of these features on the web.DataTable
is probably your best option if you need sorting and/or filtering capability
这篇关于一个很好的集合在C#绑定到一个DataGridView使用时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!