我有一个包含2个网格的主详细信息表单:customers = master,orders = detail。当我从主网格中选择新客户时,如何刷新细节?这是我的代码:
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生成的代码来完成它,但是我想用非生成的代码手动完成它,看看这个东西是如何工作的。
答案 0 :(得分:0)
创建一个方法,使用Customers作为其上下文为订单生成网格。然后创建一个重写方法,接受另一个参数(例如客户ID),然后用它重新加载数据网格。