3

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 生成コードの助けを借りてそれを行うことができましたが、このことがどのように機能するかを確認するために、生成されていないコードを手動で実行したいと考えています。

4

1 に答える 1

0

Customers をコンテキストとして使用して、注文のグリッドを生成するメソッドを作成します。次に、別のパラメーター (顧客 ID など) を受け入れるオーバーライドされたメソッドを作成し、それを使用してデータ グリッドをリロードします。

于 2013-04-22T07:19:35.250 に答える