关闭其他表单时,如何在用户控件中刷新dataGridView

时间:2018-08-23 16:08:34

标签: c# datagridview user-controls

我有一个包含按钮的主窗体,每个按钮都将您带到不同的用户控件 在产品用户控件内部,有产品的网格视图和添加按钮,用于打开添加表单

我的问题:单击添加表单的关闭按钮时,我想刷新用户控件中的gridview

main form

user control which appears when clicking products buttons

form to add product

主要形式:

  `private void btnHome_Click(object sender, EventArgs e)
    {
        UC_Home uch = new UC_Home();
        AddControlsToPanel(uch);
    }
private void btnProducts_Click(object sender, EventArgs e)
    {

        UC_Products ucp = new UC_Products();      
        AddControlsToPanel(ucp);

    }
  private void AddControlsToPanel(Control c)
    {
        c.Dock = DockStyle.Fill;
        panelControls.Controls.Clear();
        panelControls.Controls.Add(c);

    }`  

//用户控制代码

enter code here

BL.CLS_Products prd = new BL.CLS_Products();
public UC_Products()
{
    InitializeComponent();
    dataGridView1.DataSource = prd.GetAllProducts();

}

private void btnOK_Click(object sender, EventArgs e)
{

    using (FRM_AddProduct frm = new FRM_AddProduct())
    {
        frm.ShowDialog();


    }
}

//添加产品的形式

    BL.CLS_Products prd = new BL.CLS_Products();
    public FRM_AddProduct()
    {
        InitializeComponent();


        cmbo_CAT.DataSource = prd.GetAllCategories();
        cmbo_CAT.DisplayMember = "Description_CAT";
        cmbo_CAT.ValueMember = "ID_CAT";


    }


    private void button4_Click(object sender, EventArgs e)
    {

        this.Dispose();


    }
private void btnOK_Click_1(object sender, EventArgs e)
    {
        insertData();

    }

0 个答案:

没有答案