在我们的项目中,我们正在使用
虽然在我开始使用LIST后我现在使用了LIST(感谢gosha),我将代码更新为BINDINGLIST 初始化网格的相关代码部分是:
// New repository instance by UOW (unit of work)
repXtraGridAddXtraEditor = new RepositoryObject.DesignLayer.XtraGridViewAddXtraEditorRep(UOW, true);
// new bindinglist and fill it
blAddXtraGridEditor = new BindingList<BusinessObject.DesignLayer.XtraGridViewAddXtraGridEditor>(repXtraGridAddXtraEditor.Query(t => t.XtraGridViewId == XtraGridViewId).ToList());
// BindingSource bsource to be filled by blAddXtraGridEditor
bSource = new BindingSource(); // { DataSource = XtraGridViewXtraGridEditorList};
bSource.DataSource = blAddXtraGridEditor;
// PASS İT TO GRID
grdXtraGridAddXtraEditor.DataSource = bSource;
现在
是AWARE OF EACH OTHER,这意味着当我们从网格中删除记录时,它也会从Bindingsource和bindinglist中删除
当我们从网格中删除一行时
// Delete from grid ( from screen)
gvwXtraGridAddXtraEditor.DeleteRow(gvwXtraGridAddXtraEditor.FocusedRowHandle);
//reflect changes to DB
UOW.Db.SaveChanges(); // WHICH MAKES NOTHING :)
对保存对Db的更改的结果没有影响的其他代码:
bSource.EndEdit();
blAddXtraGridEditor.ResetBindings();
bSource.ResetBindings(false);
UOW.Db.SaveChanges();
删除不会反映到EntityFramework(和或UOW)
换句话说,网格和实体框架彼此不了解。
提前全部谢谢
答案 0 :(得分:0)
您调用ToList方法以获取记录。 IList接口不支持其更改的通知。你需要IBindingList。使用DbExtensions.ToBindingList方法获取它。此方法是ObservableCollection<T>
类的扩展方法。您应该使用它来返回您的数据源。我在DevExpress上找到了Building a simple Expense Tracker application using Grid Control for Windows Forms. Part 1. Creating a new Data Bound application.文章,可以在这里提供帮助。