Trap form closing

G

Gavin

Hi All

I have a project that has 2 forms, the main form displays various sql
data items and the second form is for editing / updating 1 particular
table.

I would like to refresh a dataset on from 1 when form 2 closes. How
would I trap that event?

All ideas welcome

Gavin
 
A

Armin Zingler

Gavin said:
Hi All

I have a project that has 2 forms, the main form displays various sql
data items and the second form is for editing / updating 1 particular
table.

I would like to refresh a dataset on from 1 when form 2 closes. How
would I trap that event?

All ideas welcome

Depends. Are the Forms shown modeless or modally? Do both always exist?
Where are they created?

In general, you can use the Addhandler statement to attach to an event
handler, but where and how to get the reference to the other Form depends on
the answers to the questions above.

Armin
 
G

Guest

In form2, handle the Closing event. In that event handler, call a public
method in form1 that does whatever you want.
 
P

Phill. W

Gavin said:
I would like to refresh a dataset on from 1 when form 2 closes.
How would I trap that event?

The Form's Closing Event is the one you're after, but it's only part
of the problem.

In Form 1, expose a Public method that will cause the DataSet to be
refreshed, as in :

Class Form1
. . .
Public Sub RefreshDataSet()
' Refresh DataSet
End Sub

When you instantiate Form2 (from Form 1, presumably) pass a
reference to the original Form. Many ways to do this, but a Public
property might be easiest, as in

Class Form2
. . .
Public WriteOnly Property CallingForm() As Form1
Set( Value as Form1 )
m_oCaller = Value
End Set
End Property
. . .
Private m_oCaller as Form1 = Nothing

then, back in Form1

Sub SomewhereInForm1()
Dim f as New Form2

f.CallingForm = Me
f.Show()
End Sub

In Form 2, handle the Closing Event and call the above method,
as in

Class Form2
. . .
Private Sub Form_Closing( _
ByVal sender as Object _
, ByVal e as System.ComponentModel.CancelEventArgs _
) Handles Form2.Closing

m_oCaller.RefreshDataSet()

End Sub

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top