Edit level mismatch in AcceptChanges

Edit level mismatch in AcceptChanges

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

CrikeyMoses posted on Tuesday, May 08, 2012

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)

   int from;
   int to;
   if (dest >start)
      from=start; to=dest-1;
      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)ModelIdea).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

RockfordLhotka replied on Tuesday, May 08, 2012

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.

Mr X replied on Wednesday, May 23, 2012

I had the same problem using regular lists.  Solved it by adding

ManageObjectLifetime =



in my viewmodel's factory method.

Copyright (c) Marimer LLC