I think you are missing a step on unbinding the data cleanly
prior to calling save. Look at the project tracker’s any form –
you will code to unbind data before saving. What you did I think was not
work-around, but something that needs to be done.
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: Cosmin
[mailto:cslanet@lhotka.net]
Sent: Wednesday, April 16, 2008 8:53 AM
To: Sergey Barskiy
Subject: [CSLA .NET] .net binding framework or csla problem? or mine :)
Hi,
I've got a simple hierarchy:
Customer
Orders<Order>
OrderItems<OrderItem>
Using CSLA 3.0.4
I've got 2 grids on the UI one with the Orders bound to customer.Orders and the
other one with details bound to customer.Orders.OrderItems. Binding is done
trhough 2 binding sources not directly.
Didn't need to do anything to syncronize the 2 grids which was nice.
The problem:
When I bind the interface to data I also do
customer.BeginEdit() like in the project tracker example. This works fine until
after I accept the changes and try to rebind. Exception thrown is "edit
level missmatch in CopyState". I debugged CSLA code and noted that when I
call ApplyChanges or CancelChanges the OrderItem objects don't decrement their
editlevel to 0. The orderitems grid is actually calling BeginEdit on the first
element everytime I select a row in the Ord ersGrid.
The problem occurs only when you use a grand child colection bound like I
explained above. In case of child colections there is no issue.
I worked around it by calling EndEdit() on the OrderItemsBindingSource.Current
in OnSlectedRowChanged event of the OrdersGrid.
Am I doing it the wrong way or there is an issue with the databinding framework
or csla?
Thanks,
Cosmin Onea
I was just trying to help, man. Did you trace into UndindBindinSource
to see what Current is pointing to and check edit level after Current.Apply/Cancel
edit?
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: Cosmin
[mailto:cslanet@lhotka.net]
Sent: Wednesday, April 16, 2008 10:08 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: .net binding framework or csla problem? or
mine :)
Hi Sergey,
Belive me I did it the proper way. I unbound all the bindingsources,
apply/cancel edit and then bind again. I copied and adapted the code from PT.
Private Sub RebindUI(ByVal saveObject As Boolean, ByVal rebind As Boolean)
.................................................................................................
UnbindBindingSource(OrderItemsBindingSource, saveObject, False) 'Here it
doesnt decrement the edit level of the first order item in the list. In case I
dont touch the ordersgrid it does decrement it.
UnbindBindingSource(OrdersBindingSource, saveObject, False)
UnbindBindingSource(CustomerBindingSource, saveObject, True)
OrdersBindingSource.DataSource = CustomerBindingSource
OrderItemsBindingSource.DataSource = OrdersBindingSource
Try
........................ Cancel/Apply
Changes....................................................
Catch
Finally
CustomerBindingSource.ResetBindings(False)
OrdersBindingSource.ResetBindings(False)
OrderItemsBindingSource.ResetBindings(False)
End Try
I just noticed, if I don't touch the OrdersGrid and save the
customer everything works fine. If I select any row it throws an
exception after save when I do BeginEdit() again in BindUI() Method.
Could you please try it first before replying anything. I exhausted all my
possibilities and left with the work around above.
Cosmin.
Cosmin,
There was a discussion before on this (http://forums.lhotka.net/forums/thread/20590.aspx).
The solution to this problem is similar to your workaround. We wired a handler to the CurrentChanged event of the ordersBindingSource. In this handler, EndEdit() must be called on the orderItemsBindingSource.
Cheers,
Herman
Copyright (c) Marimer LLC