Click here to Skip to main content
14,364,487 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have one form that i set to the IsMdiParent=true now i want to open the child form on parent form button click event then the child form having one textbox and one button.....now the issue is i can't get the value of the textbox in the parent form on child form button click event.how can i do this?
Posted
Comments
ali_heidari_ 12-Feb-13 3:14am
   
you want share some data between two form?
Shekhar Reddy.N 12-Feb-13 3:45am
   
Ya,exactly but one is parent and another one is child form
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi,

try like this,
TextBox txt = (TextBox)childForm1.ParentForm.Controls["txtbox1"];
// txtbox1 ID or name of textbox
// childForm1 is the object of the child form
if(txt !=null)
{
   MessageBox.Show(txt.Text.Trim());
}


hope it helps.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

maybe this is good way :
make a property in child form as parent;
private ParentForm parent;
public ParentForm Parent
{
get{return parent;}
set{parent=value}
}

well you have parent form object as a member of your child form whith this property.
then use this code in parent form:
ChildForm child=new ChildForm();
child.Parent=this;
child.Show();


with this , you have access to parent form members in your child form!
hope help !
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100