CancelEdit Funnyness : Not decrementing EditLevel()?

CancelEdit Funnyness : Not decrementing EditLevel()?

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


awbacker posted on Tuesday, July 29, 2008

I have written a little sample application that pokes and prods a binding source, an IEditableBusinessObject, and displays the state of that bindingsource/business-object in a window to the side (events, BS properties, bindable fields & EditLevel).

The issue I am having is that CancelEdit() does not decrement the EditLevel, as far as I can tell.  It works fine when I implement INotifyPropertyChange directly in my object and use *that*, but not when using PropertyHasChanged()?  I think there is something I am missing!  

ApplyEdit() does seem to save the changes and decrement the EditLevel fine, though.

Here are the steps (button clicks actually) I take:
  1. Bind new object (makes new instance, sets DataSource=_item)
  2. BindingSource.EndEdit() (resets item EditLevel to zero)
  3. _item.BeginEdit()
  4. ...modify the object if I want ...
  5. _item.CancelEdit() (undoes changes correct)
  6. EditLevel Shows = 1, .Save() Fails

The changes I made get backed out, actually, but the EditLevel "(item as IEditableBusinessObject).EditLevel " does not change, and calling Save() gives the infamous "this item is still being edited" error message.

I noticed this because originally I had implemented INotify on a POCO, and later added BusinessBase<Of Item>.  It worked at the start, but removing my INotifyPropertyChanged and using the BusinessBase "broke" it, if you can call it that.  

It is also misbehaving through the bindingSource.CancelEdit() in the same way.  

Any idea what I might be doing wrong?  

// Andrew

Thanks, Rocky, for CSLA.  MS really screwed this one up, as I am sure you know.

P.S, This text edit area does not work properly in FF 3.  Any key that has an action in a web page (slash,up,down,etc) is handled directly by FF, skipping the text edit.  So, i cant navigate, type slash (or apostrophe!), and so on.  URG!  I resorted to typing this in an external editor (EditPlus), so sorry for any spelling issues.

RockfordLhotka replied on Tuesday, July 29, 2008

A couple things.

First, the only versions where you are likely to have any luck at all are 3.0.4 and 3.5.1 - they have the best data binding support. Don't waste your time with any other versions.

Second, (and this is discussed many times in other threads) you must understand the following rules:

  1. The BindingSource will always elevate the edit level of the object that has currency. If you call CancelEdit(), it does an immediate BeginEdit()
  2. You must never call BeginEdit/CancelEdit/ApplyEdit manually on the business object while it is data bound

Third, you may want to look at the RootChildGrandchildWinFormTest sample (http://www.lhotka.net/cslacvs/viewvc.cgi/samples/trunk/RootChildGrandchildWinFormTest/). You can use TortoiseSVN to get it directly from the repository (http://www.lhotka.net/cslanet/Repository.aspx).

These concepts are discussed in the Using CSLA .NET 3.0 ebook, along with the code in PTWin that safely unbinds an object from a BindingSource (thanks to the first rule this is not so easy).

Fwiw, Miguel Castro just checked in a new extender control for CSLA .NET 3.6 that should handle the unbinding/rebinding mess automatically - making it easy to implement Save/Cancel buttons.

awbacker replied on Tuesday, July 29, 2008

Thanks for the response, though I'm sure you get a lot of these from us who don't know the proper google keywords =)

The reason this has been an issue for me is that I am working in a wizard framework, and need to undo changes if a user goes back (on certain steps), but keep the objects databound when going foward.  The basics were working, but I was concerned that I could get into trouble at some point without knowing it; Hence the little simulator =) 

I'll keep playing with it, but I think I see what I need to do, now. 

Sorry, again, for the redundant question, but thank you for answering so kindly.

//Andrew

As for the forum, it's no a big deal.  I'll set the site up in IETab and just use it that way =)  CS isn't the easiest to upgrade, as I know from others who have tried.


Codelines replied on Tuesday, February 24, 2009

The link http://www.lhotka.net/cslacvs/viewvc.cgi/samples/trunk/RootChildGrandchildWinFormTest/ is inaccessible. Do you have another link?

RockfordLhotka replied on Wednesday, February 25, 2009

I rearranged the samples for better organization – please remember that these links go directly into the live source repository.

 

I suggest starting here:

 

http://www.lhotka.net/cslacvs/viewvc.cgi/samples/trunk

 

and navigating down through the folder structure into the CslaNet area, and either cs or vb depending on your language choice. Some samples are only in one language or the other, and I don’t remember which language(s) that one uses.

 

Rocky

 

From: Codelines [mailto:cslanet@lhotka.net]
Sent: Tuesday, February 24, 2009 7:05 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CancelEdit Funnyness : Not decrementing EditLevel()?

 

The link http://www.lhotka.net/cslacvs/viewvc.cgi/samples/trunk/RootChildGrandchildWinFormTest/ is inaccessible. Do you have another link?

rsbaker0 replied on Tuesday, February 24, 2009

RockfordLhotka:

...

  1. You must never call BeginEdit/CancelEdit/ApplyEdit manually on the business object while it is data bound

...

Does this also apply if you have disabled the IEditableObject interface? My guess would be no since the BO will now ignore any BeginEdit, etc. calls from the data bindings.

RockfordLhotka replied on Wednesday, February 25, 2009

I’m sure the rules are different if you disable IEditableObject. That is honestly not an area I’ve explored, so I can’t say exactly what happens in that case – you’ll need to figure that out.

 

Rocky

 

 

From: rsbaker0 [mailto:cslanet@lhotka.net]
Sent: Tuesday, February 24, 2009 10:12 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CancelEdit Funnyness : Not decrementing EditLevel()?

 

Image removed by sender.RockfordLhotka:

...

  1. You must never call BeginEdit/CancelEdit/ApplyEdit manually on the business object while it is data bound

...

Does this also apply if you have disabled the IEditableObject interface? My guess would be no since the BO will now ignore any BeginEdit, etc. calls from the data bindings.



RockfordLhotka replied on Tuesday, July 29, 2008

awbacker:

P.S, This text edit area does not work properly in FF 3.  Any key that has an action in a web page (slash,up,down,etc) is handled directly by FF, skipping the text edit.  So, i cant navigate, type slash (or apostrophe!), and so on.  URG!  I resorted to typing this in an external editor (EditPlus), so sorry for any spelling issues.

That's unfortunate. But then this version of Community Server is several years old now. It is great that the web is "standards based", but I guess standards only last a couple years before changing Smile [:)]

The challenge is that it took about 6 hours of work for Magenic to upgrade its internal forums to the new version, and they were reasonably current. I shudder to think how many hours of work it will take me to upgrade this version to anything current...

Copyright (c) Marimer LLC