I'm using CSLA 4.2 for Silverlight.
I have a List of objects TownList : BusinessListBase<TownList, Town>.
I want to re-order the Towns, therefore i have a dragable grid, on the viewmodel i catch the event and basically do the following.
public void MoveInList(int start, int count, int dest)
if (dest >start)
Town t = Model[start];
Model.Insert(dest - 1, t);
///// Some more code that does the same thing...
for (int i = from; i <= to; i++)
((Town)Model).SortOrder = i;
This works fine until i want to Save or Cancel, then i get the error msg Edit level mismatch in AcceptChanges/UndoChanges.
I know the issues is with Model.RemoveAt and Model.Insert
DataGrid controls generally put a child object in 'edit mode' when the user enters the row bound to that child. They sometimes take the object out of edit mode when the user leaves the row - and the Silverlight datagrid control is pretty good about that.
But you are doing drag-and-drop right? That might be defeating or interfering with the datagrid control's normal behavior.
I could see, for example, how the datagrid might see the user's initial click as entering the row, so it puts the child object into edit mode. Then the user drags the item out, and you do a drag-drop implementation. But it is quite possible that at no point does the datagrid realize the user has left the row, so it wouldn't ever take the child object out of edit mode.
Additionally this is tricky, because when you remove an item from an editable collection the item is marked for deletion - and I suspect you don't want that. I think that inserting the same item might remove it from the deleted list - but you'll need to either test that, or look in the BusinessListBase code to see what happens.
I had the same problem using regular lists. Solved it by adding
in my viewmodel's factory method.
Copyright (c) Marimer LLC