473,394 Members | 1,800 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,394 software developers and data experts.

Parent Child Relationships

Hello, Thank you for reading this post.

Please forgive my ignorance. This may be a simple question but am having
trouble finding a straight answer.

I need pass data from my Child Window back to my parent window. What is the
best way to do this?

In C++ I would do this:

MainDlg * dlgParent; // in child's header
......
ChildWindow dlg; // in MainDlg
dlg.dlgParent = this;
dlg.doModal();
...........
then I could access everything directly:
dlgParent->userName = "USERNAME"; // in Child window
dlgParent->password = "PASSWORD";
I tried using the 'this' pointer and catching a ref to it in C#, but the
compiler doesn't let me do that.

Any ideas? Thank you all.

Rob K
Jan 6 '06 #1
3 1328
"=?Utf-8?B?Um9iS2lubmV5MQ==?=" <Ro********@discussions.microsoft.com>
wrote in news:FB**********************************@microsof t.com:
I need pass data from my Child Window back to my parent window. What
is the best way to do this?


What I've always done is access parameters on the Child from the Parent.

So for example, you have a child window. It's defined by a class. In that
class, create public accessors to retrieve the values you want, something
like..
public class ChildWindow : System.Windows.Forms
{
...
...
public string Username
{
get { return textBoxUserName.Text; }
}
public string Password
{
get { return textBoxPassword.Text; }
}
}

then when you create this window, you would do something like...

....
ChildWindow cw = new ChildWindow();
string username, password;
if (cw.ShowDialog() == DialogResult.OK)
{
username = cw.Username;
password = cw.Password;
}
....
-mdb
Jan 6 '06 #2
Thanks Michael! That makes so much sense!

I was in a mindset for some reason (probably staring at this screen for too
long already today) that it needed to be done the other way.

Thats perfect though. Thank you so much.

Rob K

"Michael Bray" wrote:
"=?Utf-8?B?Um9iS2lubmV5MQ==?=" <Ro********@discussions.microsoft.com>
wrote in news:FB**********************************@microsof t.com:
I need pass data from my Child Window back to my parent window. What
is the best way to do this?


What I've always done is access parameters on the Child from the Parent.

So for example, you have a child window. It's defined by a class. In that
class, create public accessors to retrieve the values you want, something
like..
public class ChildWindow : System.Windows.Forms
{
...
...
public string Username
{
get { return textBoxUserName.Text; }
}
public string Password
{
get { return textBoxPassword.Text; }
}
}

then when you create this window, you would do something like...

....
ChildWindow cw = new ChildWindow();
string username, password;
if (cw.ShowDialog() == DialogResult.OK)
{
username = cw.Username;
password = cw.Password;
}
....
-mdb

Jan 6 '06 #3
Parent frm;
frm = (Parent)this.MdiParent;
"Michael Bray" wrote:
"=?Utf-8?B?Um9iS2lubmV5MQ==?=" <Ro********@discussions.microsoft.com>
wrote in news:FB**********************************@microsof t.com:
I need pass data from my Child Window back to my parent window. What
is the best way to do this?


What I've always done is access parameters on the Child from the Parent.

So for example, you have a child window. It's defined by a class. In that
class, create public accessors to retrieve the values you want, something
like..
public class ChildWindow : System.Windows.Forms
{
...
...
public string Username
{
get { return textBoxUserName.Text; }
}
public string Password
{
get { return textBoxPassword.Text; }
}
}

then when you create this window, you would do something like...

....
ChildWindow cw = new ChildWindow();
string username, password;
if (cw.ShowDialog() == DialogResult.OK)
{
username = cw.Username;
password = cw.Password;
}
....
-mdb

Jan 7 '06 #4

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

Similar topics

9
by: jon wayne | last post by:
OK! I had this nagging doubt Consider (without worrying abt access specifiers) class Kid : public Parent{...}; Parent::someFunc() { Kid k; }
0
by: JJ | last post by:
Hi All, I am trying to Add nodes in code behind and am having problems with the parent child relationships. I get a Use of unassigned local variable error . I have the local variables defined...
4
by: Danny Tuppeny | last post by:
Hi all, I've been trying to write some classes, so when I have a parent-child relationship, such as with Folders in my application, I don't have to remember to add a parent reference, as well as...
1
by: Mr Newbie | last post by:
Sorry to bother you guys but I have another questions related to DataSets. I'm almost there now, so I dont expect to bug you much more ( Hopefully ). I have Master / Details tables with...
3
by: reachsamdurai | last post by:
Is it possible to determine the list of child/parent tables for a particular table from any system catalog tables? Using the syscat.tables I'm able to retrieve the no of dependent parent/child...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
4
by: mikemiller.innova | last post by:
In Visual Studio 2005 SP1, I added a DataSet item into my project. I added 3 tables from SQL that have data and relationships. I added 2 lookup columns (lkp) to the DllVersions table in the...
8
by: Rick | last post by:
VS 2005 I' m setting up a parent/child datagridviews in a form. I am doing a lot of this by hand coding in order to get the feel of things. I want a change in the parent table to trigger a...
4
by: hellboss | last post by:
Hi everyone ! Im using sq05 I have a set of table which goes to 5 levels of Transation , ex: Parent 1 Parent 2(Child of Parent1) Parent 3(Child of Parent2) Parent 4(Child of Parent3)...
2
by: ChaoticDALO | last post by:
Hello, I am wondering if this is possible. If I have a parent class and a child that inherits the parent, the child can access a parents member function right? Well let's say we are in the parent...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...

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.