I have a MDI child (FormA) form that opens and displays a dataGridView
.
The user has the ability to make changes to a record in the database by opening another form (FormB) that is outside of the MDI. Meaning that it is called with FormB.ShowDialog()
rather than FormB.Show().
FormA has an activated event that I want to be thrown when the user returns from FormB. I do this to refresh the datagridview's datasource.
It seems that FormA never loses focus and I need to in order for the activated event to be thrown when the user returns. Is this by design? How can I achieve this functionality?
EDIT
FormB is called from FormA's MDI Parent. not FormA itself.
Why do you need Activated
event at all? The FormB.ShowDialog()
opens FormB
in a modal state, so execution of the code in the calling form FormA
is interrupted.
See the sample (to use in the FormA
):
using (FormB frm = new FormB())
if (frm.ShowDialog(this) == DialogResult.OK)
{
// here FormB is closed by user.
}
EDIT
Since FormB
is opened from the MDI parent, you can save the currently active form to variable and then pass the execution to it. Try this in the MDI parent form:
FormA saveForm = ActiveMdiChild as FormA;
using (FormB frm = new FormB())
if (frm.ShowDialog(this) == DialogResult.OK)
{
if (saveForm != null)
saveForm.UpdateDataGridView(); // Call the method of a previously active form.
}
You can also try the ActivateMdiChild
method to activate a child form.