Click here to Skip to main content
15,900,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

Hi,

try like this,
C#
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.
 
Share this answer
 
maybe this is good way :
make a property in child form as parent;
C#
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:
C#
ChildForm child=new ChildForm();
child.Parent=this;
child.Show();


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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900