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

  • Thread starter Thread starter Karl Rhodes
  • Start date Start date
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.
 
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.
 
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.
 
Back
Top