CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Edit level mismatch in AcceptChanges

rated by 0 users
Not Answered This post has 0 verified answers | 2 Replies | 2 Followers

Top 500 Contributor
17 Posts
CrikeyMoses posted on Tue, May 8 2012 4:27 AM

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.RemoveAt(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

All Replies

Top 10 Contributor
9,270 Posts

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.

Rocky

Top 500 Contributor
31 Posts
Mr X replied on Wed, May 23 2012 10:47 AM

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

ManageObjectLifetime =

 

false;

in my viewmodel's factory method.

Page 1 of 1 (3 items) | RSS

Copyright (c) 2006-2010 Marimer LLC. All rights reserved.
Email admin@lhotka.net for support.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems