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,
Ross
Start Free Trial