Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

how to auto-refresh form A when form B is closed

Hi all,

might sound a silly question, but I can't get it right:
I have a form A containing a listview with the names of persons and a button triggering a form B to appear (showdialog method) to enter name, etc of a new person and save the data to a db.
Here's my question: how can I auto-refresh the listview in form A, after saving the data and closing form B. In other words which event, ... in form A (!, so not the close event of form B)  should solve this problem..?
I had already implemented a refresh button, but an auto-refresh would be more elegant.

Any help would be welcome lads!

Hans V.

Hans V.
Wednesday, January 28, 2004

Look at the Activated event. It fires whenever the form regains focus (therefore, also when the form loads for the first time).

Brian Kavanaugh
Wednesday, January 28, 2004

But be aware that 'activated' also triggers after selecting a date from the drop-down calendar on a date-time picker.

Ron Porter
Wednesday, January 28, 2004

I considered the activated event, but the problem with it is that it is fired each and every time form A has focus again. In my case this means that the listview is re-built every time...

Hans V.
Wednesday, January 28, 2004

Maybe I have misunderstood but it appears that you are showing form B from form A. So you should have something like this in your button click event:

Dim frm as New FormB(args)

If frm.ShowDialog(Me) = DialogResult.OK Then
    'The data was saved. Do your refresh here.
    'The dialog was cancelled or the save failed? Do something else.
End If

Also, while it is hard to get out of some of the habits of VB6 you should try not to use base class events inside a derived class. You should use the OnXXX method overrides. The events are really for using outside your class.

So in your example if you were using Show instead of ShowDialog and needed later notification when FormB was closed you would wire up the Closed event from your instance of FormB in your FormA but inside FormB you would override the OnClosed (and call MyBase.OnClosed inside it to ensure the Closed event was fired properly).

Stephen Martin
Wednesday, January 28, 2004

*  Recent Topics

*  Fog Creek Home