C# DataGridView.DataSource difference between usin

2019-02-23 02:02发布

I find that I can just set the DataGridView.DataSource directly to the DataTable without using the BindingSource in between, which is what all of the tutorial i seen so far is using. So what is the difference between thrse two?

1条回答
2楼-- · 2019-02-23 02:36

Some information here on how the use of a BindingSource is an improvement to the old way of binding directly to a DataTable.

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

In summary:

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.

查看更多
登录 后发表回答