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
BindingSource Refresh
提问by
I have 2 classes i.e CustomerOrder
and Customer
class
has a reference to a collection of orders.
I use master detail BindingSource
s.
我有2类,即CustomerOrder
与Customer
类有订单的集合的引用。我使用 master detail BindingSource
s。
My problem is when I use the lazy load pattern
for orders my detail BindingSource
is not updated.
我的问题是当我对订单使用延迟加载模式时,我的详细信息BindingSource
没有更新。
UI
用户界面
BindingSource1.datasource = GetCustomers();
BindingSource2.DataMember = "Orders";
BindingSource2.datasource = BindingsSource1;
So in my datagridView1
Click event
所以在我的datagridView1
Click 事件中
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);