In winform, refresh the parent window when closing the window (the window that originally opened this window)

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.