在winform中,关闭窗口时刷新父窗口(原来打开此窗口的窗口)

如何在关闭窗口时刷新父窗口(原来打开此窗口的窗口,不一定是mdi窗口), 这种事情在b/s里很简单,但在winform里却不那么好办。因为你不能关闭第一个窗口时再打开另一个窗口,如果这样的话新窗口就一起被关闭了。但是正因为这样,我们可以让刷新的动作在关闭子窗口时进行,当然所有的动作是在父窗口中进行的。晕,不知道说明白了没有。
还是看一下例子吧
public partial class Customer : Form
    {
        public Customer()
        {
            InitializeComponent();
        }

        private void customerBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.customerBindingSource.EndEdit();
            this.customerTableAdapter.Update(this.oadepotDataSet.Customer);

        }

        private void Customer_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“oadepotDataSet.Customer”中。您可以根据需要移动或移除它。
            this.customerTableAdapter.Fill(this.oadepotDataSet.Customer);  //请注意这里

        }

        private void SearchBtn_Click(object sender, EventArgs e)
        {
            DataTable dt=customerTableAdapter.GetDataByKey("%"+QueryTextBox.ToString()+"%");
            customerDataGridView.DataSource = dt;
        }

        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
        {
            //打开新窗口
            Form addForm = new AddCustomer();
            addForm.Owner = this;
            addForm.ShowDialog();
            this.customerTableAdapter.Fill(this.oadepotDataSet.Customer); //关键就在这里
                        
        }

请注意上面的两行红字,问题就在这里。不关子窗口什么事,所有的动作都在父窗口中完成。

猜你喜欢

转载自www.cnblogs.com/cnote/p/9058575.html