Click here to Skip to main content
15,881,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Afternoon Ladies and Gents.

I have an visual basic MDI Form Application that allows users to view and add enquiries. I cannot seem to update a gridview contained in one form from another form.

The workflow of the application is as follows

Work Flow Description

1) The parent MDI (called 'Form1') opens

2) When Form1 is initiated it opens another form called 'frmEnquiryBrowser'

3) frmEnquiryBrowser contains a data grid view (called grdEnquiryView) of the current enquiries

4) Form1 also contains a menu strip item that opens a form called 'frmAddEnquiry'

5) The user adds a new enquiry via the frmEnquiry form.

6) When the frmEnquiry saves and closes I wish to have the open frmEnquiryBrowser gridview' to refresh or update with the added enquiry.

I hope this makes sense?

I have tried several methods such,

- Making the grdEnquiryView refresh method public and calling it from frmAddEnquiry
- Instantiating frmEnquiryBrowser as a form and trying to access it this way.
- Everything else I could scrape from Google

It seems that because the frmAddEnquiry has not been opened as a dialogue from frmEnquiryBrowser i cant update it's gridview.

Any help would be much appreciated.
Posted

This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

However, I would strongly advice not to use MDI. Here is the idea: who needs it, 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? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
—SA
 
Share this answer
 
Thanks! Some really good information there. I don't think i have written a desktop app since about vb6. I have a lot to catch up on.

Thanks!
 
Share this answer
 
As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

—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