tags:

views:

60

answers:

2

I am trying to understand how to implement MVC in winforms so I have put together the following;

1.A main form which is divided into 2 panes (left/right) the left pane will display a list of customers.
2.An order details form which will list all the orders placed for the selected customer on the main form.This order details form will be displayed in the right pane of the main form.

Now, I have defined a view interface for each and a presenter. How should the order details presenter get a hold of the selected customer in the other view?

A: 

u need a publish and subscribe mechanism.

each view can announce its state changes (selectionchange event for example)

interested components can subscribe to those events

this decouples the two views - it means u could have a additional panes that shows the web page of the customer, graph of order history, photo of salesman, ....

pm100
In terms of MVP would it be the order details presenter that would have to subscribe to the main view event, if so how would it achieve this.
David
A: 

a) define an event - say selectionchange. If should be high level and expressed in terms of the model data

b) each view with a selection (your left pane for example) exposes this event

c) any view that wants to subscribe (your right pane for example) attaches itself to the event exposed by (b)

You should read up on defining and using events (most good c# books will have this)

Where it gets interesting is then having some form of brokerage system so that consumers can find event publishers, this removes the need for (c) to know the name of (b)

For your simple 2 pane system what I have described is maybe overkill, but it will be interesting to implement and adds more long term flexibility

pm100