Error "Edit level mismatch in AcceptChanges" when save a Editable Root Collection

Error "Edit level mismatch in AcceptChanges" when save a Editable Root Collection

Old forum URL: forums.lhotka.net/forums/t/12638.aspx


QuangBH posted on Wednesday, May 21, 2014

My project using CSLA 4. I am using a GridView to binding and update data. However when I update data after user edit on gridview. I always get an error : "Edit level mismatch in AcceptChanges"

The way I done it is:

Bars_Coll items = Bars_Coll.GetBar_Coll();

gridview.datasource = items;

after user edit a cell. I update by:

items.applyEdit();

items.Save();

This is the way that I learned from thread: http://forums.lhotka.net/forums/p/11468/53194.aspx 

Thank,

ajj3085 replied on Thursday, May 22, 2014

Are you using dynamic list or a normal business list? The normal case it's that the grid called ApplyEdit for you when the user leaves the row, not the cell. A dynamic list will then call safe for you, a normal list will not. Both will call ApplyChanges. So you shouldn't need to do either. It you really are calling this aww the cell loses focus, that's not the standard behavior of grids and will likely confuse users.

JonnyBee replied on Sunday, May 25, 2014

Not quite sure what you want to accomnplish but it seems you should rather use the DynamicRootBindingList stereotype that will automatically save when user moves to a new row. 

This error message is a classic one in Windows Forms as you cannot call Save on an object that has active databinding. You must always make sure that the object is not bound to any datasource/bindingsource before you can save an object. And also remember that Save returns a new instance of the obnect to "rebind" to the UI. 

When DataBinding is active it will call BeginEdit/EndEdit/CancelEdit a many times ("under the hood") and DataBinding assumes it has full control of the actual object. See also: http://msdn.microsoft.com/en-us/library/system.componentmodel.ieditableobject(v=vs.110).aspx 

Copyright (c) Marimer LLC