I implemented the MVP triad using a passive presentation template, i.e. the view contains only simple getters and setters. However, I am having problems separating view data from model data. In particular, when processing a change in state of a view.
The triad is used so that the user can select a part from the list. A list of parts is provided by the model, each of which is uniquely identified by a unique identifier.
Suppose the parts look like this:
class Part
{
int ID;
String partCode;
String description;
double voltage;
}
The view displays a list for the user and allows them to select a part
The list is displayed in the DataGridView, and part is selected by clicking on the row in the dataGridView.
, , DataTable, . DataTable , DataSource DataGridView.
class Presenter
{
IView _view;
IModel _model;
_view.Data = _model.GetFilteredData();
}
class Model
{
public DataTable GetFilteredData()
{
}
}
class View
{
public DataTable Data
{
set
{
this.dataGridView.Source = value;
}
}
}
. View DataGridView.
, , - , .
, , - .
, ( ) ( ) .
:
1) DataTable, , , . . , , ( ).
2) , . , , , , , ( ) . ( ).
public int RowIndexSelected { get; private set; }
private void gridParts_CellEnter(object sender, DataGridViewCellEventArgs e)
{
if (SelectedPartChangedEvent != null)
{
RowIndexSelected = e.RowIndex;
SelectedPartChangedEvent();
}
}
3) (2). , . ID . dataGridAdapters.
public PartSelectDataGridAdapter(IPartSelectView view, PartCollection data)
{
_view = view;
_data = data;
_view.SelectedPanelChangedEvent += HandleSelectedPartChanged;
}
void HandleSelectedPartChanged()
{
int id = _data[_view.RowIndexSelected].ID;
if (SelectedPartChanged != null)
{
SelectedPartChanged(id);
}
}
3, , .
- ?