how do I pass a parameter or argument from one windows form to another?

K

Karl Rhodes

I have an application which uses mutliple forms for different tasks,
all of which are mdi child forms to the applications MDI Parent form.

One of these child forms (form1) will be used to select a record from
somewhere within a hierarchy (using a treeview and listbox to narrow
down the search) and then the details from this record should be
displayed on an entirely different child form (form2) by the click of
a button.

What I want to know is how do I get this click of the button to open a
new form, passing over the ID value of the record selected?

I'm sure it has something to do with constructors, but as I've never
done it, I don't know how.

Any sample code for the form2's constructor, and how to open and pass
this value to form2 will be greatly appreciated.
 
Z

zacks

I have an application which uses mutliple forms for different tasks,
all of which are mdi child forms to the applications MDI Parent form.

One of these child forms (form1) will be used to select a record from
somewhere within a hierarchy (using a treeview and listbox to narrow
down the search) and then the details from this record should be
displayed on an entirely different child form (form2) by the click of
a button.

What I want to know is how do I get this click of the button to open a
new form, passing over the ID value of the record selected?

I'm sure it has something to do with constructors, but as I've never
done it, I don't know how.

Any sample code for the form2's constructor, and how to open and pass
this value to form2 will be greatly appreciated.

You don't need to muck with the new form's constructor. Just create a
property in the new form and after you instantiate the new form and
before you show it, set the value of the property to the value you
want to pass to the new form. Then after the new form is shown it can
access the value from it's own local property.
 
K

Karl Rhodes

You don't need to muck with the new form's constructor. Just create a
property in the new form and after you instantiate the new form and
before you show it, set the value of the property to the value you
want to pass to the new form. Then after the new form is shown it can
access the value from it's own local property.

Perfect... Just what I was after.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top