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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Correct' way to pass a parameter from one form to another

Status
Not open for further replies.

mercenguk

Programmer
Dec 1, 2006
8
GB
Hi All,

I need to pass a parameter from one form to another.

For example, suppose I have a form containing a grid control that gives me a list of customers.

I would like to click on one of the rows and open a new form to display all the customer's details.

If I pick up the CustomerId field from the grid, I can pass it as a parameter to the second form and use it to filter my dataset.

I was wondering which is the correct 'OO' way to accomplish this.

Many thanks,

MercEng

 
It depends I guess on how you do it. I'm not sure there's a particularly correct way to do it. I can:

1) Access the variable (as long as it is public) directly from the other form by prefixing it with the form name. Easiest and probably no one will blame you for taking this road, especially considering most are "get it done right" types more than "get it right but it has to fit all known theories, etc".
2) Probably the more formal structure for OO is to encapsulate the customer detail form in a function that has the customer id passed to it as a parameter and make it the only public thing to the form. Think something similar to how the dialog functions work. Great when finished, but a lot more work to get there.

The main thing, I think, though, is that only very anal people are really going to care what path you take to get to the desired solution.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top