How to track changes in dataGridView and transfer them to Presenter?
-
I'll use it.
WinForms
♪Entity Framework
♪Code First
♪Disconnected Entity
♪ At the same time, I'm trying to realize the pather. MVP♪There's a uniform on it.
dataGridView
♪ How do we proceed with the continuation of the changes in the Dana database? We need to track changes somehow.dataGridView
and turn them into Presenter♪Now there's nothing better to mind than to respond to an event.
CellEndEdit
design the object and transfer it to the controller. But maybe there's a way better?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);
}
-
In WinForms, binding collections are used
BindingList
var list = new List<Person>() { new Person { Name = "Joe", }, new Person { Name = "Misha", }, }; var bindingList = new BindingList<Person>(list); var source = new BindingSource(bindingList, null); grid.DataSource = source;
Minimum change
bindingList
It's supposed to be in the dried. Reverse the idea, too, check it out.FS: If there are no policy restrictions, I would not use WinForm, which has not evolved a long time. WPF is more comfortable, even though it was a long time ago.