Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send data from parent form to child form

Status
Not open for further replies.

tbreslin

Programmer
Jul 25, 2008
1
US
I have a project with a Parent Form and a child form and I want to send data(a field) from the parent form to the child form. Can anyone give me an example of the code to do that?

Thanks
 
You can try:

1. Creating a parameter in the child's form constructor, and the field is passed upon creating the child.

Example:
Code:
private string s;

public ChildForm( string s2 ){
  InitializeComponent();
  s = s2;
}

OR

2. Create a public method to pass the field.

Example:
Code:
private string s;

public void SetField( string s2 ) {
  s = s2;
}

In Parent Form:
Code:
ChildForm cs = new ChildForm();
cs.SetField( "something" );

OR

3. If the Parent Form is an MDI Container, you could use the MDIChildren property. It returns a list of forms that are the parent's children.

|| ABC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top