Trying to implement an application on WinForms through MVP

There are two View-forms: mainView and combForm, the latter gives information about checking cells for their correctness (correctness of entering a passport, phone, etc.). It looks like a checkbox list: "Check for correct input: - Passport - Phone - Mail" After selecting, a list with marked parameters is sent to the model, where the cells of a certain column are searched (depending on the parameter) and checked for correctness. If the data is entered correctly, the cell is filled with a certain color, if not, the cell remains with the standard color.

The problem is that the DataGridView, which knows how to paint the cells, is in a different form (in the mainView), and in the model I, according to the idea, can only operate on the model data - not dgv. Tell me how to process the data in the model and transfer it to the view.

A piece of code from the model with the check parameters:

foreach (DataGridViewRow row in dataGridView.Rows) //как видно, я тут использую dgv, что некорректно, потому что я не имею доступа из модели к dgv { switch (row.Cells["Код категории"].Value) { case 1: if (Regex.IsMatch((string)row.Cells["Класс"].Value, @"^0\S*", RegexOptions.IgnoreCase)) { row.Cells["Ошибки"].Value += "Не правильное заполнение поля \"Класс\""; row.Cells["Класс"].Style.BackColor = Color.Cyan; row.Cells["Код категории"].Style.BackColor = Color.Cyan; } break; } } 

If instead of dgv.Rows I substitute DataTable, then how will I give information to dgv about which cells should I paint over?

I hope clearly explained.

  • one
    Presenter has access to both the model and the view (datagrid). It is the presenter that determines the correctness of the data (possibly referring to another class / layer) and colors the cells. Not? - Alexander Petrov

0