By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

Passing data from one form to another when both forms are loaded

P: n/a
How can I pass data from one child form to another? I have two forms, one
(formX) that holds a datagrid (with the results of a query) and another
(formY) that consists of many textboxes. I'd like to pass, for example, a
row from formX to the textboxes of FormY. In this case, since both child
forms are already loaded (both forms are loaded when the MDI loads), I don't
know how to reference formY from within formX.

Is that possible?
Thanks.
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Jim,

Based on my understainding, you want to find a way to pass data from one
child form to another child form in MDI application.

To pass data to another form, you should have a reference of that form. For
your applicaiton, I think you should create a public property for parent
form, which stores all the child forms' reference. Then each child form can
refer other child form through the public property.

I write a sample like this:

In ParentForm:

public ArrayList FormList=null;
private void ParentForm_Load(object sender, System.EventArgs e)
{
FormList=new ArrayList();
FormX fx=new FormX();
fx.MdiParent=this;
fx.Show();
FormList.Add(fx);

FormY fy=new FormY();
fy.MdiParent =this;
fy.Show();
FormList.Add(fy);
}

For FormY, because its TextBox is a private variable, you should expose it
through property or method, like this:

public void SetText(string str)
{
this.textBox1.Text =str;
}

Then, in FormX, you can pass data like this:

private void button1_Click(object sender, System.EventArgs e)
{
ParentForm pf=(ParentForm)this.MdiParent;
foreach(object obj in pf.FormList)
{
Form f=(Form)obj;
if(f.Name.Equals("FormY"))
{
FormY fy=f as FormY;
fy.SetText("good");
}
}
}

===================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #2

P: n/a
Hi Jim,

Have you tried my suggestion? Do you still have any concern?

Please feel free to let me know, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.