tags:

views:

163

answers:

4

Hello,

I have a method where the user can search for a article number and if its available in the database the articlenumber gets bound to a BindingList. Now I want to let the user know if the article is not available in database. How do I do that the right way?

Just pass the message errorMessage to my interface method?

Presenter: string errorMessage; _view.ErrorMessage(errorMessage);

View: public void ErrorMessage(string errorMessage) { MessageBox.Show(errorMessage); }

Would you do it the same way?

A: 

Yes dear, its very much similar to my code :)

Prashant
A: 

That's what I do.

Another way I've read about would be for the model to know how to show an error (perhaps by an ErrorMessagePresenter) so the error is detached from the original presenter.

I haven't really found a use for that, for me, it always ends in the presenter and view implementing both interfaces.

Lennaert
A: 

In the case of error messages I would call some base functionality. This way you could choose wether to update the status window on the bottom left and/or display a modal message box.

In the presenter: _windowManager.NoItemFound(errorMessage)

In the window manager: _statusBox.Text = errorMessage; MessageBox.Show(errorMessage);

Dries Van Hansewijck
A: 

We bubble an event. In the presenter you register that event:

public event PresenterEventHandler Message;

And then raise it like so:

PresenterEventArgs pe = new PresenterEventArgs("Error message", Status.Error);
this.Message(this, pe);

Then in the view:

protected override void OnInit(EventArgs e)
{
    this.presenter = new MyPresenter(this, MyBusinessService.Instance);
    this.presenter.Message += new PresenterEventHandler(presenter_Message);
}

void presenter_Message(object sender, PresenterEventArgs pe)
{
    // display error message
}

You can pass different types of statuses back to the view in this way, and not just error messages. We have Success, Error, Locked, Warning, Help.

Junto