我有一个包含两个网格的主从表单: 客户 = 主, 订单 = 从。当我从主网格选择一个新客户时,如何刷新从网格?以下是我的代码:
public partial class Form1 : Form
{
AutoLotEntities context = new AutoLotEntities();
BindingSource customerBindingSource;
BindingSource orderBindingSource;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
customerBindingSource = new BindingSource();
orderBindingSource = new BindingSource();
customerBindingSource.DataSource = context.Customers;
orderBindingSource.DataMember = "Orders";
orderBindingSource.DataSource = customerBindingSource.DataSource;
grdCustomers.DataSource = customerBindingSource;
grdOrders.DataSource = orderBindingSource;
}
}
我通过在Form1.Desginer.cs中使用IDE生成的代码成功完成了它,但我希望手动编写非生成的代码来查看这个东西是如何工作的。