473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trap form closing

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

Nov 21 '05 #1
3 1643
Gavin schrieb:
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
Nov 21 '05 #2
In form2, handle the Closing event. In that event handler, call a public
method in form1 that does whatever you want.

"Gavin" wrote:
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

Nov 21 '05 #3
"Gavin" <ga********@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: RAJ | last post by:
hi plz tell me how to know "how window is going to close"... i have to right code for X button of forms... plz telll me thanks bye
1
by: Chris Bruce | last post by:
In my application I need a way to distiguish between the following events: 1. When a user closes an MDI child window. 2. When the user closes the MDI parent window which subsequently closes the...
6
by: Gary Miller | last post by:
Does anyone know how to detect a modeless form on closing by the form that invoked the modeless form? form.Show();
1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
2
by: Bob | last post by:
In a winform with a datagridview using cellvalidating event but also have a save button that is located on a tablebindignnavigator. The behaviour I observe is that if the cellvalidating issues a...
6
by: Robert Dufour | last post by:
On my form if the user clicks the upper right hand corner to close the form I want to trap that event and do a check to see if closing is allowed, if not, I want to stop the form closing action. ...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
3
by: mtczx232 | last post by:
I have TabControls that Hold Forms on his TabPges (this make me easy to give ability to Designing each form in his IDE window). When form x is in middle of Edit Data Mode, I going to prevent:...
2
by: John | last post by:
Hi I have an app comprising of the start-up form. I need to run a process when the application closes. What event do I need to trap for this purpose? Thanks Regards
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.