一个很好的集合在C#绑定到一个DataGridView使用时 [英] A good collection to use when binding to a DataGridView in C#

查看:225
本文介绍了一个很好的集合在C#绑定到一个DataGridView使用时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最好的集合数据绑定列表在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 a DataGridView : it implements INotifyCollectionChanged, not IBindingList, and the DataGridView doesn't know about INotifyCollectionChanged. It is intended for WPF bindings and is not used in Windows Forms
  • BindingList<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屋!

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