473,779 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Returning values from a form

I have an application I'm working on where one form will open another.
This newly opened form needs to return a value based on the users actions.
My forms are not modal. I have seen discussions about overridding the
DialogResult, however I believe this will only work in a modal form
situation.

I have code where I've added a custom event to the child form called
ReturnValueSet. The form that opens this form can then subscribe to this
event and trap the value that was set if it wishes. The child form then
must be coded to raise this event when it is closing. This method works,
but I would prefer to use a more standard approach is there is one.

Does anyone have suggestions?

Thanks
Dan
Sep 1 '08 #1
7 2212
On Mon, 01 Sep 2008 11:50:46 -0700, Dan Tallent <sp**@microsoft .comwrote:
[...]
I have code where I've added a custom event to the child form called
ReturnValueSet. The form that opens this form can then subscribe to
this
event and trap the value that was set if it wishes. The child form then
must be coded to raise this event when it is closing. This method
works,
but I would prefer to use a more standard approach is there is one.
If you just want the client form to retrieve the value when the child form
is closed, then I'd say the client form should just subscribe to the
FormClosed event. Then the child form should set some property that the
client form can retrieve when the FormClosed event is raised (the child
form would of course make sure this property is suitably set when it's
closed, before the FormClosed event is raised).

That said, other than the name of the event, what you've done is actually
a reasonably standard approach, depending on the semantics you want. The
..NET convention would be to have a property, and then an event with the
same name as the property, plus "Changed".

You could either only raise the "Changed" event when the form closes, or
you could allow for the client form to monitor changes as the user
provides input. Either way, that would be reasonable too.

Pete
Sep 1 '08 #2
Thanks for the quick response.

If I use the FormClosed event does this cause a potential issue that the
form may of already been released and therefore the property being
unavailable?

If using the FormClosed event is safe, do you know if the code within the
child forms FormClosed event fires before it raises the event to the parent?

Thanks
Dan


"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Mon, 01 Sep 2008 11:50:46 -0700, Dan Tallent <sp**@microsoft .com>
wrote:
>[...]
I have code where I've added a custom event to the child form called
ReturnValueSet . The form that opens this form can then subscribe to
this
event and trap the value that was set if it wishes. The child form then
must be coded to raise this event when it is closing. This method
works,
but I would prefer to use a more standard approach is there is one.

If you just want the client form to retrieve the value when the child form
is closed, then I'd say the client form should just subscribe to the
FormClosed event. Then the child form should set some property that the
client form can retrieve when the FormClosed event is raised (the child
form would of course make sure this property is suitably set when it's
closed, before the FormClosed event is raised).

That said, other than the name of the event, what you've done is actually
a reasonably standard approach, depending on the semantics you want. The
.NET convention would be to have a property, and then an event with the
same name as the property, plus "Changed".

You could either only raise the "Changed" event when the form closes, or
you could allow for the client form to monitor changes as the user
provides input. Either way, that would be reasonable too.

Pete

Sep 1 '08 #3
Dan Tallent wrote:
Thanks for the quick response.

If I use the FormClosed event does this cause a potential issue that the
form may of already been released and therefore the property being
unavailable?

If using the FormClosed event is safe, do you know if the code within the
child forms FormClosed event fires before it raises the event to the parent?

Thanks
Dan


"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
>On Mon, 01 Sep 2008 11:50:46 -0700, Dan Tallent <sp**@microsoft .com>
wrote:
>>[...]
I have code where I've added a custom event to the child form called
ReturnValueSe t. The form that opens this form can then subscribe to
this
event and trap the value that was set if it wishes. The child form then
must be coded to raise this event when it is closing. This method
works,
but I would prefer to use a more standard approach is there is one.
If you just want the client form to retrieve the value when the child form
is closed, then I'd say the client form should just subscribe to the
FormClosed event. Then the child form should set some property that the
client form can retrieve when the FormClosed event is raised (the child
form would of course make sure this property is suitably set when it's
closed, before the FormClosed event is raised).

That said, other than the name of the event, what you've done is actually
a reasonably standard approach, depending on the semantics you want. The
.NET convention would be to have a property, and then an event with the
same name as the property, plus "Changed".

You could either only raise the "Changed" event when the form closes, or
you could allow for the client form to monitor changes as the user
provides input. Either way, that would be reasonable too.

Pete

You could use the FormClosing event.

Sep 1 '08 #4
Your client (or parent) form won't have released the instance, so the
instance count is not zero, and therefore it is not disposed. You won't
have an issue getting a property on the object from your instance.

"Dan Tallent" <sp**@microsoft .comwrote in message
news:e$******** ******@TK2MSFTN GP04.phx.gbl...
Thanks for the quick response.

If I use the FormClosed event does this cause a potential issue that the
form may of already been released and therefore the property being
unavailable?

If using the FormClosed event is safe, do you know if the code within the
child forms FormClosed event fires before it raises the event to the
parent?

Thanks
Dan


"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
>On Mon, 01 Sep 2008 11:50:46 -0700, Dan Tallent <sp**@microsoft .com>
wrote:
>>[...]
I have code where I've added a custom event to the child form called
ReturnValueSe t. The form that opens this form can then subscribe to
this
event and trap the value that was set if it wishes. The child form
then
must be coded to raise this event when it is closing. This method
works,
but I would prefer to use a more standard approach is there is one.

If you just want the client form to retrieve the value when the child
form is closed, then I'd say the client form should just subscribe to the
FormClosed event. Then the child form should set some property that the
client form can retrieve when the FormClosed event is raised (the child
form would of course make sure this property is suitably set when it's
closed, before the FormClosed event is raised).

That said, other than the name of the event, what you've done is actually
a reasonably standard approach, depending on the semantics you want. The
.NET convention would be to have a property, and then an event with the
same name as the property, plus "Changed".

You could either only raise the "Changed" event when the form closes, or
you could allow for the client form to monitor changes as the user
provides input. Either way, that would be reasonable too.

Pete

Sep 1 '08 #5
Sounds good.. now I have a plan.

Thanks
Dan

"Family Tree Mike" <Fa************ @ThisOldHouse.c omwrote in message
news:uw******** ******@TK2MSFTN GP03.phx.gbl...
Your client (or parent) form won't have released the instance, so the
instance count is not zero, and therefore it is not disposed. You won't
have an issue getting a property on the object from your instance.

"Dan Tallent" <sp**@microsoft .comwrote in message
news:e$******** ******@TK2MSFTN GP04.phx.gbl...
>Thanks for the quick response.

If I use the FormClosed event does this cause a potential issue that the
form may of already been released and therefore the property being
unavailable?

If using the FormClosed event is safe, do you know if the code within the
child forms FormClosed event fires before it raises the event to the
parent?

Thanks
Dan


"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******* ********@petes-computer.local. ..
>>On Mon, 01 Sep 2008 11:50:46 -0700, Dan Tallent <sp**@microsoft .com>
wrote:

[...]
I have code where I've added a custom event to the child form called
ReturnValueS et. The form that opens this form can then subscribe to
this
event and trap the value that was set if it wishes. The child form
then
must be coded to raise this event when it is closing. This method
works,
but I would prefer to use a more standard approach is there is one.

If you just want the client form to retrieve the value when the child
form is closed, then I'd say the client form should just subscribe to
the FormClosed event. Then the child form should set some property that
the client form can retrieve when the FormClosed event is raised (the
child form would of course make sure this property is suitably set when
it's closed, before the FormClosed event is raised).

That said, other than the name of the event, what you've done is
actually a reasonably standard approach, depending on the semantics you
want. The .NET convention would be to have a property, and then an
event with the same name as the property, plus "Changed".

You could either only raise the "Changed" event when the form closes, or
you could allow for the client form to monitor changes as the user
provides input. Either way, that would be reasonable too.

Pete


Sep 1 '08 #6
On Mon, 01 Sep 2008 12:38:19 -0700, Dan Tallent <sp**@microsoft .comwrote:
Thanks for the quick response.

If I use the FormClosed event does this cause a potential issue that the
form may of already been released and therefore the property being
unavailable?
As Mike says, the object itself will still be around (though not for the
reason he states). However, it is true that the form will have been
disposed by that time, so your property should not access the things
within the form that themselves are disposed when the form is disposed (in
particular, the various controls).

Typically, you'd address this by keeping the data of interest in a member
field that is updated either as the user provides input to the form, or by
simply initializing it in the OnFormClosing() override in the child form
(depending on when you want the property to be valid).
If using the FormClosed event is safe, do you know if the code within the
child forms FormClosed event fires before it raises the event to the
parent?
The FormClosed event is raised by the base OnFormClosed() method. The
OnFormClosing() method is called before the OnFormClosed(), so assuming
that's where you initialize the property, it will be valid when an event
raised by OnFormClosed() is raised, regardless of where in OnFormClosed()
you raise the event. If you somehow initialize the property in
OnFormClosed(), you'll want to do so before calling the base
OnFormClosed().

Pete
Sep 1 '08 #7
Peter, I think I follow what you are saying, but didn't realize that was
happening behind the scenes. Thanks for educating me today!

Mike

"Peter Duniho" <Np*********@nn owslpianmk.comw rote in message
news:op******** *******@petes-computer.local. ..
On Mon, 01 Sep 2008 12:38:19 -0700, Dan Tallent <sp**@microsoft .com>
wrote:
>Thanks for the quick response.

If I use the FormClosed event does this cause a potential issue that the
form may of already been released and therefore the property being
unavailable?

As Mike says, the object itself will still be around (though not for the
reason he states). However, it is true that the form will have been
disposed by that time, so your property should not access the things
within the form that themselves are disposed when the form is disposed (in
particular, the various controls).

Typically, you'd address this by keeping the data of interest in a member
field that is updated either as the user provides input to the form, or by
simply initializing it in the OnFormClosing() override in the child form
(depending on when you want the property to be valid).
>If using the FormClosed event is safe, do you know if the code within the
child forms FormClosed event fires before it raises the event to the
parent?

The FormClosed event is raised by the base OnFormClosed() method. The
OnFormClosing() method is called before the OnFormClosed(), so assuming
that's where you initialize the property, it will be valid when an event
raised by OnFormClosed() is raised, regardless of where in OnFormClosed()
you raise the event. If you somehow initialize the property in
OnFormClosed(), you'll want to do so before calling the base
OnFormClosed().

Pete
Sep 1 '08 #8

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

Similar topics

6
14034
by: Krackers | last post by:
How do you write a function which returns a reference to an array. I can only get a function to return a copy of the array itself. I've had a look at some other threads in this group an the return value of a function acts like 'by Val' returning the value only (except for objects) can you make it return a reference instead? cheers, Krackers
2
1596
by: Graham Blandford | last post by:
Hi all, Quickie - I hope. I already know how to use a forms New() Sub to receive parameters from a calling class - but I don;t know how to return values... Anyone know the recommended method for doing this? Thanks, Graham
18
2145
by: cppaddict | last post by:
Hi, Is it considered bad form to have the subscript operator return a const reference variable? If not, what is the proper way to do it? My question was prompted by the code below, my problematic attempt to implement a subscript operator that returns a const reference. The dubious code is marked at the end. <code>
1
1700
by: Ben | last post by:
I have a Tabular form bound to a table. The purpose of this form is to get times from a timer and record them in a field. The timer dumps the time automatically through a serial port. When the time is recorded it goes to the next record. Sometimes a user may have to skip a record and come back. All of this is no problem and works great. I have 3 buttons that will set any penalties in a record. The person just needs to hit a button to...
2
1494
by: MLH | last post by:
I have the following tasks to perform on an unbound form. I want them to run every time I return to the form. For reasons not at issue here, I do not close the form with a docmd.close command. I leave the form open and set its visible property to false. When I need to return again to the form, I do so with the openform statement. Here are the tasks I want to run when I first open the form and everytime I return to it... 'Initialize...
1
4017
by: John Chorlton | last post by:
I've been attempting to pass a chunk of data back from a child Windows form using public properties on the form and have been getting some odd errors. I wanted to return a row of data to avoid creating many public properties on the form to do the same thing. At first I tried returning a DataViewRow. This worked fine until I reached the phone field on the parent table and the code Child form public DataRowView SelectedAddres ge ...
1
3567
by: vinodkus | last post by:
I M BEGINNER IN ASP I WANT TO RETURN TOTAL RECORDS FROM A TABLE. THERE ARE TWO FORMS CLASS1.ASP AND CLASS2.ASP THROUGH FIRST FORM I JUST POST THE NAME OF TABLE SO I M WRITING THE CODE OF CLASS2.ASP <!--#Include File = "Include/iecon.inc"--> <html> <head> <meta http-equiv="Content-Language" content="en-us">
0
4102
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me with my problems. Now for my new little problem,I had a problem posting the values from checkbox fields to a database and thats the obstacle I overcame. Now the second part is my new problem is that I want that the next time that page loads for...
1
2899
by: Max58kl | last post by:
Hi I am trying to setup a form that automatically sends the form values via email to a specific address. I have uploaded the script, which when I run loads a page with the following error message: CGI Error The specified CGI application misbehaved by not returning a complete set of HTTP headers. According to the tutorial I am using the only thing I needed to change was the
7
11083
Haitashi
by: Haitashi | last post by:
I have a form that calls a function using the onClick event in the submit button. I would like this function to return false if the username is taken. The the original function, which I've tested, returns the correct info when the "checkUname" button is clicked. However, it always returns false. I want to return false ONLY if the username is taken. Original: $("#checkUname").click(function(){ var datastring=...
0
10139
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9931
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6727
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5504
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.