views:

17

answers:

1

I 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?

A: 

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.

Hans Passant
Thanks Hans.. It's working fine
Jeyavel