当选定的主项更改时如何刷新详细信息?

3

我有一个包含两个网格的主从表单: 客户 = 主, 订单 = 从。当我从主网格选择一个新客户时,如何刷新从网格?以下是我的代码:

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生成的代码成功完成了它,但我希望手动编写非生成的代码来查看这个东西是如何工作的。

1个回答

0
创建一个方法,使用“客户”作为上下文来生成订单网格。然后创建一个重载的方法,接受另一个参数(例如客户ID),然后重新加载您的数据网格。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接