Multiple Forms, Closing Events and Sub Routines

MagicEvmeister

New member
Joined
May 21, 2010
Messages
2
Programming Experience
1-3
Hi All

I have googled high and low to find an answer to this but I must be searching wrong. Hopefully someone can help me.

I have an application which has a listview displaying some items that are stored in a SQL Compact database. I am using a second form to add new items to this list directly into the database. When the second form closes I want to call the sub in my first form to refresh the list from the database.

How can I get it to fire the form1 sub routine on the close event of form2

Any help is greatly appreciated
 
Why bother refreshing from the database? You've already got the data in your app so why not use that? Your dialogue shouldn't even know that the database exists. You should have a DataTable in your main form. You use the dialogue to receive new data from the user which you then add to that DataTable. You then save the changes in the DataTable to the database using the same DataAdapter that you used to populate it in the first place, AND you use the contents of the DataTable to update ListView. All that is done in the main form.
 
Perhaps a more detailed explanation of exactly why I'm doing it this way will make more sense.

Amongst other things the program monitors the status of various windows services. The services being monitored are displayed in a listview box along with their current status. A second form opens to list all of the services installed so you can choose new services to be monitored.

When a new service is added to the list to be monitored it's identifying information is inserted directly into the database, then the second form closes. Upon this I wish to fire a subroutine in the first form which will refresh the list of services being monitored and fetch their current status.

I have the required sub routines to perform this function but I need to know how to fire it when the second form closes.
 
I still don't think that that's the best way to go about it but it's your app.

If the second form is being displayed by calling ShowDialog then you know that the form has closed as soon as ShowDialog returns. If it's being displayed by calling Show then you need to handle its FormClosed event.
 
Back
Top