473,467 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pass a value from a child form to a Parent

Rob
I have a control (Button) on a Parent form which opens a Windows form... all
I want to do is pass a value from the child form back to the parent... it
should be so simple... i.e.
ParentFormName.Textbox1.text=ChildFormName.TextBox WhatEver.Text... but
nothing like this works.

Any ideas ?
Jun 27 '08 #1
5 4205
"Rob" <ro***@yahoo.comschrieb
I have a control (Button) on a Parent form which opens a Windows
form... all I want to do is pass a value from the child form back to
the parent... it should be so simple... i.e.
ParentFormName.Textbox1.text=ChildFormName.TextBox WhatEver.Text...
but nothing like this works.

Any ideas ?
General answer: To access an object, you need a reference.

The specific answer depends on many things. First, is the 2nd Form shown
modally (Showdialog)? When do you want to access the other form? Which
event? Writing abstract and reusable code, it's usually not common
practice to access the caller from the callee.
Armin

Jun 27 '08 #2
Rob,

As it is a dialogform, than it is as simple to create a friend property in
your dialog and get that when the dialog is done.

Cor

"Rob" <ro***@yahoo.comschreef in bericht
news:id******************************@comcast.com. ..
>I have a control (Button) on a Parent form which opens a Windows form...
all I want to do is pass a value from the child form back to the parent...
it should be so simple... i.e.
ParentFormName.Textbox1.text=ChildFormName.TextBo xWhatEver.Text... but
nothing like this works.

Any ideas ?


Jun 27 '08 #3
On May 27, 1:34 am, "Rob" <ro...@yahoo.comwrote:
I have a control (Button) on a Parent form which opens a Windows form... all
I want to do is pass a value from the child form back to the parent... it
should be so simple... i.e.
ParentFormName.Textbox1.text=ChildFormName.TextBox WhatEver.Text... but
nothing like this works.

Any ideas ?
My personal method is to have an event on the child form that will
return the value. Then when the child form is created, the parent form
(or any other form that cares about that event) should subscribe to
that event. Then whenever the value is created / changed on the child
form the other forms will be able to act accordingly. This method also
promotes loosely couple forms, which could save some major headaches
in maintenance or reuse.

Thanks,

Seth Rowe [MVP]
Jun 27 '08 #4

A few thoughts:

Form is a class like any other class. You pass values through
properties like you would any other class.

I recommend that you separate your values from the user
interface instead of trying to access them from the controls.

In other words: When the childform class is asked to close,
clientform should grab the values from its controls and store
them in private members, accessible through properties.

One childform has closed, parentform can access the values
through those properties.

For a simple scenario like this, I would suggest that this is the
way to go.

For more complex scenarios where multiple objects need to
react to changes in one or more values, the idea of subscribing
to events has some validity (but do keep track of what object
initiated a change and what objects should just reflect the change).

VB2005 and later supports the VB6 concept of a shared default
instance of a form. I have my reservations about this. I like to
know/control whether a form is freshly initialized or reused.

When/if using ShowDialog to display the form, remember to use
..DialogResult = ... to close it instead of Me.Close.

Regards,

Joergen Bech

On Tue, 27 May 2008 01:34:39 -0400, "Rob" <ro***@yahoo.comwrote:
>I have a control (Button) on a Parent form which opens a Windows form... all
I want to do is pass a value from the child form back to the parent... it
should be so simple... i.e.
ParentFormName.Textbox1.text=ChildFormName.TextBo xWhatEver.Text... but
nothing like this works.

Any ideas ?
Jun 27 '08 #5
On May 27, 7:31 pm, "Rob" <ro...@yahoo.comwrote:
Hi

Regarding... 1) best OO choice - create a message and have the parent
subscribe to
it.

Do you have some sample code that demonstrates this ?
Rather than rewrite someone else's work this article describes it
fairly well.
http://forums.microsoft.com/MSDN/Sho...46657&SiteID=1
Jun 27 '08 #6

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

Similar topics

1
by: Filiz Duman | last post by:
Hi, I am opening a pop up window (child) from a parent window. The Child window does show a table with multiple columns and rows, each showing a value, e.g. 9 or 10 or etc. I have the values as...
3
by: Lyn | last post by:
Hi, I have been experiencing a problem passing a LIKE statement in the WHERE argument of a DoCmd.Openform statement. I have posted that issue separately. However, in an attempt to work around...
2
by: Chandru | last post by:
hi I want to know how to pass values from different forms. That is, i created one parent form. from there i opened child form modeless way. Once i close the child form i need some value from...
3
by: Chris | last post by:
Before I started to create table, etc to track unique form field record number assigments I thought I'd check to see if there is now a better way to do this in .NET. I have a parent form (table)...
3
by: Vivek | last post by:
Hi, I wish to refresh the parent form and pass the new values from child form. How can I do it? Thanks
2
by: Karl Rhodes | last post by:
I have an application which uses mutliple forms for different tasks, all of which are mdi child forms to the applications MDI Parent form. One of these child forms (form1) will be used to select...
3
by: juliusy | last post by:
I have Form1 launches Form2. On Form2, user will enter input (a string). When I click OK to close Form2, I need to have that string value populated TextBox1 on Form1 (the parent form). I only...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.