Geeks With Blogs

News QTP and Stuff
Theo Moore Questions... Morphology? Longevity? Incept dates?

CSLA. A great product that does so many things so well. I won't expound upon how much I like it at the moment, but I always feel like I should say something positive about it before I point out something odd.


I have a standard DataGridView in a WinForm application. I have a Root object (which children and grandchildren, although this isn't relevant). I am using a BindingSource for binding the two together. So, in my code, I have something like this:



Now, this should seem like pretty boilerplate CSLA, and it is. Where we run into trouble is when we save the CSLA Root (nothing peculiar there):




We get an exception in the DataPortal, which states: "Object is still being edited and can not be saved". Did some sleuthing about. Your BusinessBase has a private property called "EditLevel"' (which comes up through the inheritance chain). The edit level is incremented and decremented (sic) by things like BeginEdit, ApplyEdit, or CancelEdit (as a matter of fact, I think these are the only places it's changed). If the EditLevel is > 0, the object is still being edited. The DataPortal.Save makes this check. Trouble is, I am using BeginEdit (EditLevel =+ 1) and ApplyEdit (EditLevel =-1) one time each, so how could the EditLevel be anything but 0? Obviously, the BeginEdit is being called more than once, but how?

I removed the BeginEdit call in the first piece of code, and voila! It works. Clearly somewhere in BusinessBase, the DataGridView, and BindingSource, we are having a problem. As a work-around,I will bind the grid directly.

And for anyone who has noticed this is VB and not C#, I haven't given up on C#. I am writing a sample app for CodeCamp 3.0 in Charleston this weekend, and I am still more productive in VB.  :-)

Posted on Thursday, October 11, 2007 7:42 PM | Back to top

Comments on this post: CSLA: DataGridView + BindingSource + RootObject = HUH?

# re: CSLA: DataGridView + BindingSource + RootObject = HUH?
Requesting Gravatar...
Hey, I ran into the same thing with CSLA. I forget the exact specifics but I think the act of binding the control causes an internal .beginedit call. I think it's somewhat counter intuitive but once I realized that's how it worked I moved forward. If I needed to isolate any edits to the object I throw in an extra applyedit. You can also consider changing the "nevervisible" attribute on the editlevel property to allow for checking it in UI code.
Left by gl006 on Nov 11, 2007 1:58 PM

Comments have been closed on this topic.
Copyright © Theo Moore | Powered by: