gpt4 book ai didi

c# - BindingSource - 使用 BindingSource 有什么优势

转载 作者:太空狗 更新时间:2023-10-29 18:34:34 37 4
gpt4 key购买 nike

是什么让我使用这样的东西:

DataGridView dgvDocuments = new DataGridView();
BindingSource bindingSource = new BindingSource();
DataTable dtDocuments;

dtDocuments = MsSQL.GetDocuments(dtpOd.Value, dtpDo.Value);
bindingSource.DataSource = dtDocuments;
dgvDocuments.DataSource = bindingSource;

而不是这个:

DataGridView dgvDocuments = new DataGridView();
DataTable dtDocuments;

dtDocuments = MsSQL.GetDocuments(dtpOd.Value, dtpDo.Value);
dgvDocuments.DataSource = dtDocuments;

最佳答案

BindingSource 有很多好处,下面是其中的一些

1) 当您使用 bindingsource 将数据绑定(bind)到任何控件时,它将在双方生效。对数据源所做的任何更改都会影响控件,以及对控件会影响数据源的任何更改。您不需要从控件中获取值并再次分配给数据源

2) 您可以使用bindingsourcefilter应用于datasource

3) 您可以将一个数据源 绑定(bind)到多个控件。例如,您有表 Fruits,您将此 table 绑定(bind)到 2 DataGridView 以显示 Aplles桃子分开。使用 bindingsource Filter 属性,您可以分别显示 ApplesPeaches

4) 您可以使用 bindingsource 进行搜索、排序、编辑、过滤

您无法在基本列表中看到 bindingsource 的好处,但除了基本列表之外,您还会看到 bindingsource 的用处。

您可以获得更多信息Here

关于c# - BindingSource - 使用 BindingSource 有什么优势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41956937/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com