EditLevel error (WinForm)

EditLevel error (WinForm)

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

dg78 posted on Sunday, May 23, 2010



When everything is ok, databinding and n-level undo are marvelous but with the smallest error it is the horror.

And now it is the horror for me with an EditLevel error on a child BO.

(I use the Csla version VB 3.52 in WinForms and I don’t use managed properties).

 In Copystate (Undoable), I have an exception in  :

      If Me.EditLevel + 1 > parentEditLevel Then

        Throw New UndoException( _

          String.Format(My.Resources.EditLevelMismatchException, "CopyState"))

        Exit Sub

      End If


because EditLevel = 1 for the child and ParentEditLevel is also egal to 1.


I do :

          Dim oEmploye As Employe = Employe.NewEmploye

          Dim uc As ucEmploye = New ucEmploye(oEmploye)


No problem then in the UI, I have a button “Create a new employe”. The exception come with a click on this button.

My editable root is Employee and the child BO is Totals (which give sums of several values of payrolls). In SQL Server, there is a relationship one-one between tables Employee and Totals.

Totals is created during payroll edition and I want to display Totals in the editable Employee root UI.


First I use for the Totals child an editable root child and I have the error described above.


What do I miss ?


I know that many old posts are about that problem. I read many of them but I don’t know how to solve my problem. It is not easy and not clear.


It is my first question, my second is below :


I think it is better to use a ReadOnly Child for Totals BO. Is it possible to use a ROC for that ?

Thanks for a small sample (even in C#).


Best regards

dagware replied on Sunday, May 23, 2010

I've developed the habit of exposing the EditLevel property in all my business objects & collections, so I can write console messages for situations like this. Eventually I figure out what's causing the edit levels to get out of sync.

That's the best I can offer, which I admit isn't much. Oh, and also that you're not alone in the frustrations you feel! Good luck.


dg78 replied on Monday, May 24, 2010

Thanks Dan for your answer.

Me too I expose the EditLevel in the BO :

             Public ReadOnly Property CurrentEditLevel() As Integer


                           Return EditLevel

                    End Get

             End Property


Yes, sometimes I am frustrated with Dotnet and Csla and I think that I am not alone.

We must be patient with Dotnet and very very patient with Csla. I think it is the reason that there are no women who work with Csla (since many years I never see one on the forum).


Come back to my problem.

I found a solution (perhaps not the solution but a solution).

When I click on the button “create a new employee”, I do :


        bsEmploye.DataSource = mEmploye

        ReBindUI(mEmploye, False, True, Ok)


Before to enter on RebindUI, I have :

memploye.CurrentEditLevel = 1

memploye.MyTotals.CurrentEditLevel =1


In RebindUI, we go on  UnbindBindingSource   then  current.CancelEdit  then CancelEdit  then  UndoChanges(Me.EditLevel - 1)


Here there is :


        ' this is a child object, cascade the call

        If Not _bindingEdit OrElse TypeOf value Is FieldManager.FieldDataManager Then

           DirectCast(value, IUndoableObject).UndoChanges(Me.EditLevel, BindingEdit)

        End If


Never I go on the UndoChanges for child and it is normal because  _bindingEdit  is always True (we can undo only if it is do before).


I repeat that I don’t use managed properties so I have no FieldDataManager.


Then I saw how Rocky does when childs are BLB or even in managed properties. I found that he uses  Csla.Core.UndoableBase.ResetChildEditLevel  to synchronize editlevel for child / root.


Then I put :


        bsEmploye.DataSource = mEmploye


        Csla.Core.UndoableBase.ResetChildEditLevel(mEmploye.MyTotals, 1, True)


        ReBindUI(mEmploye, False, True, Ok)


And now it is good.

But  Csla.Core.UndoableBase.ResetChildEditLevel  is Friend then I put it Public.


Rocky, could you put this sub as Public or is it necessary to expose it in the BO ?

Dexter replied on Tuesday, May 25, 2010

Take a look at the CslaActionExtender helper class, that may be of help to you.

Copyright (c) Marimer LLC