开发者

Refresh MDI parent window datagrid after closing child window in C#.Net Windows application?

I 开发者_JAVA技巧have a MDI window with a datagridview control which is used to display a list of records in a database table(s). If the user wants to add a new record, they click "new" and a popup(Child) window displays. The popup window accepts data from the user (name, number, date, etc) and is then submitted back to the server when the users clicks an ok button. At this point I want to update the database with the new record, close the popup(child) window, and then refresh the parent window datagridview so that it reflects the newly added record that was created using the popup window.

Here is the code for open child window from MDI

frmJobControlWindow frmjobcontrol = new frmJobControlWindow();
frmjobcontrol.ShowDialog();

while child window closing event how to handle refresh MDI Parent DataGridview?


ShowDialog() returns a value that indicates what the user did with the dialog. Use it like this:

using (frmJobControlWindow frmjobcontrol = new frmJobControlWindow()) {
    if (frmjobcontrol.ShowDialog() == DialogResult.Ok) {
        // update datagrid
        //...
    }
}

Be sure to set the dialog's DialogResult property in your OK button Click event handler:

private void Ok_Click(object sender, EventArgs e) {
    // Do some stuff
    //...
    this.DialogResult = DialogResult.Ok;
}

Although it is automatic when you set the form's AcceptButton property. Setting the DialogResult also automatically closes the dialog.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜