Edit Functionality

Edit Functionality

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


ravimaran posted on Thursday, November 01, 2007

Hi,  I have built this windows form application and ran into this issue which I am not able to figure out. Here is my forms
FormA - Contatins a list of Customers
FormB - Details of a single customer ( Opens up when a customer is clicked from FormA List)
FormC - Adds customer interest and the percentage( using C1TrueDbGrid so customer can be modified from the list)
FormC is called from FormB when user click the button "Customer Interests"  and FormC has Save button.
After Save button clicked. 
Private sub btnInterest_Clicked .....
  custermerInterestList.ApplyEdit()
  FormC.Close()
end sub
The list is being saved in memory then it writes to the database when user click "Save Changes" button from FormB.
This works fine when I go from FormA to FormB then FormC.  Coming back to FormB and Save.

Then when I decided to keep the FormB open and again click "Customer Interests" I am able to edit or add new interest but when I close the FormC and Save it from FormB it does not save it to the database.  When I tried to debug it, I saw that the IsDirty Property become "True" right after I made changes but it changes back to "False" right after the form is closed! Actually its keeping the list before modified.  I am so confused why this happening.  Please help me to over come this issue.  Thank you.

RockfordLhotka replied on Thursday, November 01, 2007

You are finding that data binding is altering your object's state "for you".

If you update to CSLA 3.0.2 you will most likely get exceptions during this process, because CSLA 3.0 now throws an exception when the edit levels get out of sync. The reason for that exception is to help you debug situations like this one.

Data binding will call BeginEdit, CancelEdit and ApplyEdit automatically. You are probably seeing a case where data binding is calling CancelEdit behind the scenes, causing your object's state to be rolled back to a previous point.

The PTWin code in 3.0.2, along with some changes to CSLA, make this work reliably and help you detect edit level sync problems, and so I recommend you consider moving to that version to figure this out.

ravimaran replied on Thursday, November 01, 2007

Hi Rocky, Thanks for the reply.  Unfortunately I am not able to use CSLA.NET 3.0.2.  What really confuses me is It works the first time but for the second time it doesn't really save it.  IsDirty property is set back to false and EditLevel is not 0. 
When form loads I call BeginEdit()
When changes and before closing I call ApplyEdit()
When closing (if is not cancel) I call CancelEdit()
Please give me some advise on  how these Edit things works.  Thank you.

RockfordLhotka replied on Thursday, November 01, 2007

There’s another thread with a lot of good detail and discussion around how data binding interacts with edit levels – it was active within the past 2 weeks or so – I recommend reading through that.

 

Rocky

 

From: ravimaran [mailto:cslanet@lhotka.net]
Sent: Thursday, November 01, 2007 5:09 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Edit Functionality

 

Hi Rocky, Thanks for the reply.  Unfortunately I am not able to use CSLA.NET 3.0.2.  What really confuses me is It works the first time but for the second time it doesn't really save it.  IsDirty property is set back to false and EditLevel is not 0. 
When form loads I call BeginEdit()
When changes and before closing I call ApplyEdit()
When closing (if is not cancel) I call CancelEdit()
Please give me some advise on  how these Edit things works.  Thank you.


Copyright (c) Marimer LLC