how to return object to parent window form
how to call to open popup, and return object from another window form to caller(parent call method) when clicking button in child window.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bruce RoeserPosted Jul 1, 2010, 11:18 AM
// Mainline
ChildForm frm = new ChildForm();
MyObject obj;
frm.ShowDialog();
obj = frm.PublicObject; // Establishing a local reference to the object in the form.
// ... in ChildForm
class ChildForm as System.Whatever.Form {
public MyObject PublicObject = new MyObject();
// Somewhere in form code assign the properties to the object ...
}
I don't know of a mechanism by which a form "returns" an object to the caller of ShowDialog() however presenting the object as a public property of the child form is always how I've been able to retrieve values from the child form while it still exists.
Just keep in mind that the form itself will still live in memory if you have a reference to the public object so you might want to copy the contents of the public object in the form to a newly instantiated version of your object instead so that assignment above doesn't have to be made directly to the object (which will keep the garbage collector from getting rid of the form).
HTH,
-bruce