Click here to Skip to main content
15,913,090 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
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.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.

The child form will appear on clicking the menue.

while child window closing event how to handle refresh MDI Parent DataGridview?


Regards,
Sarthak Mishra
Posted

If it's a popup window, then the easiest way to do it is to show the window with myPopupForm.ShowDialog
That "blocks" the original form code until the user closes the pop-up.
You can then use the pop-up instance via properties to add a row to the DGV:
C#
MyPopup myPop = new MyPopup();
if (myPop.ShowDialog() == DialogResult.OK)
   {
   string name = myPop.ClientName;
   string mobile = myPop.MobileNumber;
   ...
   myDataGridView.Rows.Add(name, mobile, ...
   }
 
Share this answer
 
Comments
sarthakm 8-Sep-15 1:22am    
the main window containing grid will remain open.
on clicking the menu a new small screen will appear .if ew enter any value within it then those value will immideately get updated in the grid present in the main window.
I'll give you an alternative, much more practically useful advice: avoid using MDI.

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages,
How to Create MDI Parent Window in WPF?.

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF?,
Question on using MDI windows in WPF,
MDIContainer giving error,
How to set child forms maximized, last childform minimized.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900