C# 绑定源刷新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1147751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 09:22:59  来源:igfitidea点击:

BindingSource Refresh

c#.netwinformsbusiness-objectsbindingsource

提问by

I have 2 classes i.e CustomerOrderand Customerclass has a reference to a collection of orders. I use master detail BindingSources.

我有2类,即CustomerOrderCustomer类有订单的集合的引用。我使用 master detail BindingSources。

My problem is when I use the lazy load pattern for orders my detail BindingSourceis not updated.

我的问题是当我对订单使用延迟加载模式时,我的详细信息BindingSource没有更新。

UI

用户界面

BindingSource1.datasource = GetCustomers();
BindingSource2.DataMember = "Orders";
BindingSource2.datasource = BindingsSource1;

So in my datagridView1Click event

所以在我的datagridView1Click 事件中

if (customer.orders != null)
{
  customer.Orders = LoadOrders();
}

I appreciate any help with this.

我很感激这方面的任何帮助。

回答by Julien Poulin

Try reseting the binding:

尝试重置绑定:

BindingSource1.DataSource = GetCustomers();
BindingSource2.DataMember = "Orders";

BindingSource2.DataSource = BindingSource1;
BindingSource2.ResetBindings(true);