I have a form A with a button called 开发者_如何转开发btnA
and a datagrid.
When I click on this button, another form B opens which has a button btnB. When I click on btnB, I need to close form B and refresh form A. How do I achieve this?
Thanks.
When you create FormB
, pass a reference to FormA
class FormB : Form
{
FormB(FormA parent)
{
this.Parent = parent;
}
...
protected void btnB_Click(object sender, EventArgs e)
{
parent.RefreshGrid();
this.Close();
}
}
and then on butB click, you can close formB and access formA to refresh it.
You can use ShowDialog()
in FormA
to show FormB
. This will show FormB
modally. Then, when you close FormB
, execution will continue in FormA
on the statement after ShowDialog()
. Write your refresh code there.
精彩评论