Reputation: 314
I'm using Visual Studio 2010 to create a C# Windows Form application. In the main Form I've a button which opens secondary form using ShowDialog()
which makes some updates on the database. When user saves data and closes that form, I need to update my ListView
on main Form from database. How to trigger updates on ListView when secondary Form is closed? I tried mouse events to make update on ListView
but that is a bit late. Is there any event which I can use to achieve this?
Upvotes: 2
Views: 4382
Reputation: 17499
Looks like you want to update listview on main form as soon as user is done with changes in sub form and closes it.
If that is true, main form can subscribe a handler to subform.closing event. And in the event handler you can update listview from database.
Do not forget to unsubscribe the handler from subform.closing.
Upvotes: 0
Reputation: 2456
If you use ShowDialog() than execution continues from next string after the form was closed:
var updateForm = new UpdateForm();
updateForm.ShowDialog();
// Here it was closed
UpdateMainForm();
Upvotes: 8