.net binding framework or csla problem? or mine :)

.net binding framework or csla problem? or mine :)

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


Cosmin posted on Wednesday, April 16, 2008

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. The project is like the PTWin sample except it has a grand child collection.

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. Actually only the first item in the grid doesn't. The orderitems grid is actually calling BeginEdit on the first element everytime I select a row in the OrdersGrid.

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








sergeyb replied on Wednesday, April 16, 2008

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

cid:_2_0648EA840648E85C001BBCB886257279
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










Cosmin replied on Wednesday, April 16, 2008

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.

sergeyb replied on Wednesday, April 16, 2008

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

cid:_2_0648EA840648E85C001BBCB886257279
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.



McManus replied on Wednesday, April 16, 2008

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

Cosmin replied on Thursday, April 17, 2008

Excellent, yes CurrentChanged is better to hook.
Thanks Herman.

I'm still facing problems with this one:

What if you have a collection in the root object but you don't bind it to any bindingsource. The edit level of the first child is 2 and after applying the changes the level 1(which is wrong) and it breaks next time I begin edit.

To fix it I just bound the collection to a hidden grid and let the binding framework do the work.

Is this a problem in the UndoableBase class?

Thanks,
Cosmin

Copyright (c) Marimer LLC