【问题标题】:How to refresh the detail when the selected master item changes?选择的主条目更改时如何刷新明细?
【发布时间】:2013-04-19 16:04:25
【问题描述】:

我有一个包含 2 个网格的主明细表单:客户 = 主控,订单 = 明细。从主网格中选择新客户时如何刷新详细信息?这是我的代码:

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 生成代码的帮助下设法做到了,但我想用非生成代码手动完成,看看这个东西是如何工作的。

【问题讨论】:

    标签: c# winforms entity-framework


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-08-20
      • 2017-04-12
      • 2019-07-11
      • 1970-01-01
      • 1970-01-01
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多