How to refresh the parent window when closing the window (the window that opened the window is not necessarily an MDI window) is very simple in B/S, however, it is not so easy in winform. Because you cannot open another window when closing the first window, if so, the new window will be closed together. But because of this, we can let the refreshed action do when the child window is closed. Of course, all the actions are performed in the parent window. Dizzy. If you do not know it, it indicates that it is white.
Let's take a look at the example.
Public partial Class Customer: Form
{
Public customer ()
{
Initializecomponent ();
}
Private void customerbindingnavigatorsaveitem_click (Object sender, eventargs E)
{
This. Validate ();
This. customerbindingsource. endedit ();
This. customertableadapter. Update (this. oadepotdataset. Customer );
}
Private void customer_load (Object sender, eventargs E)
{
// Todo: This line of code loads data into the table "oadepotdataset. Customer. You can move or remove it as needed.
This. customertableadapter. Fill (this. oadepotdataset. Customer); // pay attention to this
}
Private void searchbtn_click (Object sender, eventargs E)
{
Datatable dt = customertableadapter. getdatabykey ("%" + querytextbox. tostring () + "% ");
Customerdatagridview. datasource = DT;
}
Private void bindingnavigatoraddnewitem_click (Object sender, eventargs E)
{
// Open a new window
Form addform = new addcustomer ();
Addform. Owner = this;
Addform. showdialog ();
This. customertableadapter. Fill (this. oadepotdataset. Customer); // The Key is here.
}
Pay attention to the two lines above. The problem is here. All actions are completed in the parent window without closing the Child Window.