C# DataGridView.DataSource 使用与不使用 BindingSource 的区别

标签 c# bindingsource

我发现我可以直接将 DataGridView.DataSource 设置为 DataTable,而无需在两者之间使用 BindingSource,这是我目前看到的所有教程都在使用的方法。那么这两者有什么区别呢?

最佳答案

这里有一些关于使用 BindingSource 如何改进直接绑定(bind)到 DataTable 的旧方法的信息。

http://msdn.microsoft.com/en-us/library/aa480734.aspx

总结:

The BindingSource component simplifies the developer's job by providing currency management, change notification and the ability to easily access the members in a bound list. There are, however, some other lesser-known improvements to the data binding story worth discussing, and in fact, are important additions that complement the functionality offered by the BindingSource component.

The Binding object has several new members in the .NET Framework 2.0 that enable greater control over the binding operation. For example, you can control how data is formatted in a bound control, when the data source is updated, and how null and DBNull values in the data source are handled. These new members are also supported with corresponding Add methods in the ControlBindingsCollection. You can take advantage of these additions by using the Formatting and Advanced Binding dialog box in Visual Studio or through code. In addition, the Binding object has better support for handling exceptions and errors that can occur in the binding process with the addition of the BindingComplete event.

关于C# DataGridView.DataSource 使用与不使用 BindingSource 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4433281/

相关文章:

c# - bindingsource 上的 CancelEdit 不会取消对象的所有已编辑字段

c# - 为什么 Process.Start 会意外返回 false

c# - 返回根类型的 Fluent Builder 模式

c# - 不同可能的子类的函数返回列表

c# - DataGridView 过滤使用 BindingSource(CustomClassObjects)

c# - 无法使用绑定(bind)源刷新数据 GridView

c# - JSON.NET 序列化对象,其中属性名称以点开头

c# - 时间格式

c# - 由于使用 Costura.Fody 的嵌入式程序集处理 deps.json

c# - 为什么 DataBinding 第二次不起作用?