I am using WinForms , Entity Framework , Code First , Disconnected Entity . At the same time I try to implement the MVP pattern.
There is a form, there is a dataGridView on it. How to implement save changes in the database? You need to somehow track the changes in the dataGridView and bring them to Presenter .
Now nothing better comes to mind than reacting to the CellEndEdit event, constructing an object and passing it to the controller. But maybe there is a more elegant way?
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { Goods goods = new Goods(); goods.GoodsId = (int)dataGridView1.CurrentRow.Cells[0].Value; goods.Name = dataGridView1.CurrentRow.Cells[1].Value.ToString(); goods.Price = (int)dataGridView1.CurrentRow.Cells[2].Value; goods.Descriprion = dataGridView1.CurrentRow.Cells[3].Value.ToString(); goods.Barcode = (int)dataGridView1.CurrentRow.Cells[4].Value; presenterGoods.Update(goods); }