D
Doug
Hi,
I learned a little about the model view presenter pattern at a
conference this last week and am experimenting with it. It's working
pretty well but I have a question.
I am trying to use it to reset info in a combo box. Below is some
sample code for my view interface and the presenter:
public interface IDevToolView
{
string[] Tables
{ set; }
}
public class DevToolPresenter
{
private IDevToolView _view = null;
public DevToolPresenter()
{}
public DevToolPresenter(IDevToolView view)
{
_view = view;
}
public void GetTablesForNewDatabase()
{
string [] tables = //Some code to get the string array of tables
if (tables.Length != 0)
{
_view.Tables = tables;
}
}
}
and here's what my view looks like (just the sample for what I need for
this question:
public class frmMain : Form, IDevToolView
{
public string[] Tables
{
set
{
cboTable.Items.Clear;
cboTable.Items.AddRange(value);
}
}
}
My question is around the call to Items.Clear in the Tables property.
This seems to me to violate the pattern, I should really be doing that
within the presenter if I understand the pattern correctly. However,
short of passing in the combo box itself into the presenter, I can't
seem to get around it, because I don't have any way to access
cboTable.Items directly.
Am I misunderstanding this? Is there a way around my problem?
I learned a little about the model view presenter pattern at a
conference this last week and am experimenting with it. It's working
pretty well but I have a question.
I am trying to use it to reset info in a combo box. Below is some
sample code for my view interface and the presenter:
public interface IDevToolView
{
string[] Tables
{ set; }
}
public class DevToolPresenter
{
private IDevToolView _view = null;
public DevToolPresenter()
{}
public DevToolPresenter(IDevToolView view)
{
_view = view;
}
public void GetTablesForNewDatabase()
{
string [] tables = //Some code to get the string array of tables
if (tables.Length != 0)
{
_view.Tables = tables;
}
}
}
and here's what my view looks like (just the sample for what I need for
this question:
public class frmMain : Form, IDevToolView
{
public string[] Tables
{
set
{
cboTable.Items.Clear;
cboTable.Items.AddRange(value);
}
}
}
My question is around the call to Items.Clear in the Tables property.
This seems to me to violate the pattern, I should really be doing that
within the presenter if I understand the pattern correctly. However,
short of passing in the combo box itself into the presenter, I can't
seem to get around it, because I don't have any way to access
cboTable.Items directly.
Am I misunderstanding this? Is there a way around my problem?