Nitin
Nitin

Reputation: 314

Updates on Main Form after another Form is Closed

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

Answers (2)

Manish Basantani
Manish Basantani

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

acrilige
acrilige

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

Related Questions