Advertisement

02.15.2007 at 07:19AM PST, ID: 22391462
[x]
Attachment Details

How do I refresh a 'parent' form when a 'child' closes

Asked by myxiplx in .NET Framework 2.0, Microsoft Visual Basic.Net, Visual Studio .NET 2005

Tags: parent, refresh, child

I'm writing my first application with Visual Studio 2005 in Visual Basic.  I'm struggling to update the main form of my program when a second form updates the database.

First of all, there isn't a true parent/child relationship between these forms.  I want users to be able to work on as many orders as they like at the same time, so there could be multiple copies of the details form open, and that unfortunately seems to rule out using the Parent or Owner properties.  

The main form shows a summary of current orders, the details form allows me to complete any order (which should remove it from the summary).  Also, I could be calling this same details form from many possible 'parent' forms, so I'd like to keep the approach as generic as possible.  

The best approach I've thought of so far is to add a parameter to New() on the details form, passing a reference to the form which opened it.  I can then add a custom method to the summary form and call that before the detail form closes:

Details Form:
Sub New (ByVal parent as Form)
(
   'store parent in a global variable for this form
)

Parent Form:
Public Sub UpdateMe()
(
   'Refresh the datagrid
)

The problem with this is it's very specific to the type of parent form.  Initialising the parameter of the details form as a 'Form' object means the IDE isn't happy when I try to call UpdateMe(), and I'm going to have to put a try... catch block around the call to UpdateMe() in case I ever forget to include it on a parent form.

The next alternative I thought of is to somehow monitor the 'child' form from the parent, calling the refresh function from the parent when it sees the child form close.  I'm guessing this would be possible if I attached to the process/thread used by the child form?

I've also thought of overloading the parent form's refresh() method.  Just to save me the hassle of the try..catch block in the child form, and to stop the IDE complaining ;-).

Can anyone recommend a neat & tidy way to do this?  

thanks,

RossStart Free Trial
[+][-]02.15.2007 at 07:58AM PST, ID: 18541143

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 2.0, Microsoft Visual Basic.Net, Visual Studio .NET 2005
Tags: parent, refresh, child
Sign Up Now!
Solution Provided By: Idle_Mind
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.15.2007 at 08:10AM PST, ID: 18541258

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32