Update DataGridView after Child Form Closed

后端 未结 2 1994
抹茶落季
抹茶落季 2021-01-16 04:11

I know lot of similar questions are out there. But, I\'m really new to C# so, cannot figure out how to solve this.

I have a DataGridView on main form a

2条回答
  •  情深已故
    2021-01-16 04:25

    This is just a sample, how you call the public method in main form from child form:

    public class Products : Form
    {
        public void UpdateProductList()
        {
            // do something here
        }
    
        private void buttonOpenChildFormClick(object sender, EventArgs e)
        {
            using (var addProduct = new Add_product(this)) //send this reference of MainForm to ChildForm
            {
                addProduct.ShowDialog();
            }
        }
    }
    
    public class Add_product : Form
    {
        private readonly Products _products;
    
        public Add_product(Products products) //send reference of MainForm to ChildForm
        {
            _products = products;
        }
    
        private void button1_Click(object sender, EventArgs e)
        {
            _products.UpdateProductList();
        }
    }
    

提交回复
热议问题