refresh a dataGridView from another form

◇◆丶佛笑我妖孽 提交于 2019-12-06 15:48:51

Your problem is that you're creating a new instance of Form1. Instead of new Form1 you need to pass an instance of the existing Form1 to Form2

I solved my problem with the help of @MikeH and @Sybren:

Form1:

Form2 frm = new Form2(this);
frm.Show();

Form2:

    private readonly Form1 frm1; //readonly is optional (For safety purposes)

    public Form2(Form1 frm)
    {
        InitializeComponent();

        frm1 = frm;
    }

    private void btnInsert_Click(object sender, EventArgs e)
    {
        frm1.RefreshGrid();
        this.Close();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!