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

发布于 2024-10-07 18:07:46 字数 111 浏览 5 评论 0原文

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

I found that I can just set the DataGridView.DataSource directly to the DataTable without using the BindingSource in between, which is what all of the tutorials I've seen so far are using. So what is the difference between these two?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拍不死你 2024-10-14 18:07:46

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

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

BindingSource 组件简化了
开发人员的工作是提供
货币管理、变更
通知和轻松的能力
访问绑定列表中的成员。
然而,还有一些其他
鲜为人知的数据改进
值得讨论的具有约束力的故事,并且在
事实上,是重要的补充
补充所提供的功能
通过 BindingSource 组件。

Binding 对象有几个新的
.NET Framework 2.0 中的成员
能够更好地控制
绑定操作。例如,你
可以控制数据的格式化方式
绑定控件,当数据源为
更新了,以及如何null和DBNull
处理数据源中的值。
这些新成员也受到支持
与相应的 Add 方法
ControlBindingsCollection。你可以
利用这些新增功能
使用格式和高级
Visual Studio 中的绑定对话框或
通过代码。此外,绑定
对象对处理有更好的支持
可能发生的异常和错误
在绑定过程中与
添加 BindingComplete 事件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文