名单< T> VS的BindingList< T>优势/劣势 [英] List<T> vs BindingList<T> Advantages/DisAdvantages

查看:228
本文介绍了名单< T> VS的BindingList< T>优势/劣势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以介绍一下两者的区别是我的项目。

Can someone describe what the difference between the two are for my project.

目前我有一个名单,其中,MyClass的> ,并设置BindingSource的这一点,一个DataGridView到BindingSource

Currently I have a List<MyClass> and set the BindingSource to that and a DataGridView to the BindingSource.

我已实施 IEditableObject 所以当CancelEdit叫我恢复我的对象回到它是一个 Memberwise.Clone()

I have implemented IEditableObject so when CancelEdit is called I revert my object back to what it was with a Memberwise.Clone()

会改变我的清单到的BindingList解决任何这,什么是使用的BindingList的优势是什么?

Will changing my List to a BindingList solve any of this and what are the advantages of using a BindingList?

推荐答案

A 名单,其中;&GT; 是一个简单的自动调整大小的数组给定类型的项目,与几个辅助功能(例如:排序)。这仅仅是数据,而你很可能会用它来在模型运行在一组对象的操作。

A List<> is simply an automatically resizing array, of items of a given type, with a couple of helper functions (eg: sort). It's just the data, and you're likely to use it to run operations on a set of objects in your model.

A 的BindingList&LT;&GT; 是围绕一个类型列表或集合,它实现了 IBindingList的接口的包装。这是支持双向数据绑定的标准接口中的一个。它的工作原理通过实施的ListChanged 事件,当您添加,删除或设置项被提高。绑定控件监听此事件,以便知道什么时候刷新其显示。

A BindingList<> is a wrapper around a typed list or a collection, which implements the IBindingList interface. This is one of the standard interfaces that support two-way databinding. It works by implementing the ListChanged event, which is raised when you add, remove, or set items. Bound controls listen to this event in order to know when to refresh their display.

当您设置的BindingSource的DataSource到名单,其中;&GT; ,它在内部创建一个的BindingList&LT;&GT; 来包装你的列表中。您可能要pre-包装用的BindingList&LT你的清单;&GT; 自己,如果你想要到BindingSource之外访问它,但除此之外,它是一样的。您还可以从继承的BindingList&LT;&GT; 更改项目时实施特殊的行为

When you set a BindingSource's DataSource to a List<>, it internally creates a BindingList<> to wrap your list. You may want to pre-wrap your list with a BindingList<> yourself if you want to access it outside of the BindingSource, but otherwise it's just the same. You can also inherit from BindingList<> to implement special behavior when changing items.

IEditableObject 由BindingSource的处理。它会调用BeginEdit任何执行对象,当你改变任何绑定控件中的数据。然后,您可以调用EndEdit中/ CancelEdit上的BindingSource,它会通过它传递给你的对象。移动到不同的行会调用EndEdit中也是如此。

IEditableObject is handled by the BindingSource. It'll call BeginEdit on any implementing object when you change the data in any bound control. You can then call EndEdit/CancelEdit on the BindingSource and it will pass it along to your object. Moving to a different row will call EndEdit as well.

这篇关于名单&LT; T&GT; VS的BindingList&LT; T&GT;优势/劣势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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