Infragistics & Csla 3?

Infragistics & Csla 3?

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


ajj3085 posted on Monday, June 18, 2007

Hi,

I'm trying Csla 3 to see if it helps with an issue I'm having with a grid editing an EditableRootListBase class. 

Unfortunately, it seems that the grid control simply does not behave correctly at all; any form with a grid attached to an editable collection throws the new UndoException, Edit level mismatch.

Has anyone else had these problems?

Thanks
Andy

Edit:  Looking at the code for CopyState (which is the method throwing the UndoException), it looks like its comparing the parents edit level to the current items edit level + 1.  I don't claim to understand the code, but it the plus one seems odd.  Isn't the code checking to see that the edit levels are the same?

ajj3085 replied on Monday, June 18, 2007

It seems like the problem is that I have a root object + binding source, and a child collection + binding source.  Setting the binding source to the child collection, then setting the other binding source to the root object apparently causes problems.

Reversing the order of the calls initially seems to correct this problem.  I'm going to try some other forms to see if simply changing the order in which I set the datasource for the binding sources corrects these issues.

RockfordLhotka replied on Monday, June 18, 2007

Check the code in PTWin in svn. Getting data binding to cooperate in a parent-child relationship turns out to be a bit of a challenge, but I believe the code in ProjectEdit (for example) is correct and works.

ajj3085 replied on Tuesday, June 19, 2007

I looked at the sample that came with the beta, hopefully that is similar to the svn.

It seems that you're using one binding source as the datasource for the child's binding source.  Is that the perfered method of linking the objects together?

RockfordLhotka replied on Tuesday, June 19, 2007

It is similar, but subsequent to the beta (I think – things are so busy I’m not sure about order-of-events sometimes) I worked through a couple very tough issues with data binding in Windows Forms – especially around the Cancel button – that are reflected in svn.

 

Click here to see the current c# code for ProjectEdit.

 

Click here to see the current vb code for ProjectEdit.

 

In any case, a child bindingsource should use the parent bindingsource as its data source, yes. That’s the way data binding knows about the parent-child relationship, and it is the behavior you get when doing drag-and-drop design of your form in VS.

 

Rocky

 

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Tuesday, June 19, 2007 8:42 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Infragistics & Csla 3?

 

I looked at the sample that came with the beta, hopefully that is similar to the svn.

It seems that you're using one binding source as the datasource for the child's binding source.  Is that the perfered method of linking the objects together?


ajj3085 replied on Tuesday, June 19, 2007

I've done as you suggested, and set secondary bindingsource objects to have the primary bindingsource as their datasource.  That seems to have cleared up all the issues.

The one part that was difficult was a form where I actually have a control specifically built to handle the editing of single child objects.  I had to modify the control to accept a BindingSource component instead of the child object type.

Thanks for the help.
Andy

ajj3085 replied on Wednesday, June 20, 2007

I guess I spoke too soon.  The form now loads, but I didn't try saving.

The problem is that I clone my BO ApplyEdit and save the clone.  I get UndoException however on a rebind.

The issue is that the child objects somehow get to EditLevel two, and after applying the edit, they still have an EditLevel of one.

It seems that the secondary binding source is still calling BeginEdit on the child object, even though the secondary bindingsource's datasource is the "root" bindingsource.  Since BeginEdit was never called on the child object (and thus the bindingEdit flag is still false), it does another CopyState.

Am I still doing something wrong? 

The secondary BS is on a UserControl, if that makes any difference.

RockfordLhotka replied on Wednesday, June 20, 2007

The trick is that you have to unbind, or work with an unbound copy, of the object.

 

As soon as you call bs.EndEdit() or bs.CancelEdit() the bindingsource calls BeginEdit(). Every time, and immediately. So as long as your object is bound to a bindingsource, it is (or one child is) at an elevated edit level.

 

So to save or cancel you must unbind so you can get the edit levels down to 0.

 

Rocky

 

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Wednesday, June 20, 2007 10:33 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: Infragistics & Csla 3?

 

I guess I spoke too soon.  The form now loads, but I didn't try saving.

The problem is that I clone my BO ApplyEdit and save the clone.  I get UndoException however on a rebind.

The issue is that the child objects somehow get to EditLevel two, and after applying the edit, they still have an EditLevel of one.

It seems that the secondary binding source is still calling BeginEdit on the child object, even though the secondary bindingsource's datasource is the "root" bindingsource.  Since BeginEdit was never called on the child object (and thus the bindingEdit flag is still false), it does another CopyState.

Am I still doing something wrong? 

The secondary BS is on a UserControl, if that makes any difference.


ajj3085 replied on Wednesday, June 20, 2007

Ok.. I missed the part in projectedit where you were calling EndEdit on the binding sources before doing the clone.  I've done that, and it seems to have fixed my issues..

Thanks for sticking with me on this.  It would seem I have not been working with data binding very well at all..

RockfordLhotka replied on Wednesday, June 20, 2007

Well, neither was I (or probably anyone else) until I put that code in 3.0 to throw exceptions when the edit levels got out of sync. In retrospect I really wish I’d put that code in a long time ago…

 

Rocky

 

 

From: ajj3085 [mailto:cslanet@lhotka.net]
Sent: Wednesday, June 20, 2007 12:09 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: Infragistics & Csla 3?

 

Ok.. I missed the part in projectedit where you were calling EndEdit on the binding sources before doing the clone.  I've done that, and it seems to have fixed my issues..

Thanks for sticking with me on this.  It would seem I have not been working with data binding very well at all..


Copyright (c) Marimer LLC