I have been puzzling over this for a while and I would like to hear from
those who have written quite a few windows apps as to your opinions.
I have a form that displays a grid showing a list of customers. The user
clicks one of the rows and a detail form appears that show information about
a particular customer. What is the best way to do this?
1. Have the list form in the double click method of the grid grab the key
field and pass the key field to the detail form and have the detail form
look up the record to be displayed.
int id = getKeyFieldFromGrid();
MemberDetailForm form = new MemberDetailForm(id);
form.ShowDialog();
2. Have the list form call the controller class to look up the customer id
and then pay the customer object returned to the detail form to be
displayed.
int id = getKeyFieldFromGrid();
Customer c = controller.GetCustomerById(id);
MemberDetailForm form = new MemberForm(c);
form.ShowDialog();
3. Have a field in the controller class called currentCustomer which is an
object of the Customer class, call the retrieve method from the double click
method of the grid and have the returned object stored in the
currentCustomer field in the controller and then pass the controller to the
detail form which then displays the currentCustomer object of the
controller.
int id = getKeyFieldFromGrid();
controller.GetCustomerById(id);
MemberDetailForm form = new MemberDetailForm(controller);
form.ShowDialog();
Which option best practices MVC? If there are other options please tell me
what they are.
Thanks
Bill
|