CancelEdit on child objects

CancelEdit on child objects

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


SealedClassSingleton posted on Wednesday, October 25, 2006

Hi,

I'm having a strange problem when cancelling changes on a BO with child objects. Whenever I call CancelEdit on the BO, all newly added childs are removed from the child collection (inherits from BusinessListBase), but the modifications to the existing child objects aren't gone.

Any suggestions would be helpfull.

Thx

 Bart.

JoeFallon1 replied on Wednesday, October 25, 2006

Check out the FAQ and then doa search for more info.

Basically I think your ID values are not unique.

SealedClassSingleton replied on Thursday, October 26, 2006

Hi,

Thx for your answer. I already checked the FAQ but doesn't find any info regarding this problem. In fact I don't think it has something to do with the ID value since I'm using Guid's that are generated when the child objects are created.

The problem is that the undo functionality does only half of the job: all newly added child to the BO are rollbacked correctly (in fact deleted), but the problem is that the changes to the already existing child objects aren't rollbacked to the original values...

Am I missing something and do I have to use the CancelEdit in another way or is something wrong with the FWor my BO's ?

Bart.

boo replied on Thursday, October 26, 2006

Stupid question, but I have to ask, so don't be offended.  Are you calling BeginEdit first, before the changes are made?

MSerrate replied on Friday, October 27, 2006

I guess you’re working with the DataGridView for your child objects, in this case, try the next line before the call to CancelEdit() in your cancel event:
childBindingSource.EndEdit()

I had a similar problem before, and had something to do with the Undo from the data grid (the ESC action) as it is calling to BeginEdit() too.

jeffreyice1 replied on Thursday, June 07, 2007

Ok, to make this as clear as I can. I have a child object that has two buttons (one to cancel changes and another to take the changes)  This is a single child object is to remain around (Not close) even though it is hidin. (.Visable = false) Calling the Close without keeping changes button is the following code

 

mCustomer.CancelEdit()

Me.Visible = False

Me.CustomerBindingSource.ResetBindings(False)

 

Now If I am keeping the changes I call the following code

Me.Visible = False

 

The Show win part redisplays the information as it was even though I used canceledit() function. And called the cancel edit function prior.The object seems to be still intact with the changes (And I have not destroyed the object) Just calling it up again with the Following:

 

Private Sub EditCustomerButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditCustomerButton.Click

' see if this project is already loaded

For Each ctl As Control In ContractEntryEditPanel1.Controls

   If TypeOf ctl Is CustomerEntry Then

      Dim part As CustomerEntry = CType(ctl, CustomerEntry)

      ShowWinPart(part)

    Exit Sub

   End If

Next

This should use the exiting object instead of loading it from the database.

 

Question is How does the object react without being destoryed and reloaded with the canceledit function?

CancelEdit only seems to work with closeing of the object and does not concider that the object can be cancel changes on the fly and keeped in memory for future referance.

Im thinking that I have to add inital values on the load from database and on initalization, then on canceledit restore these values in the project.libarary if the object is to hang around. Is this the way to go?

I Hope that I explained this right.

 

Iceman

 

ajj3085 replied on Friday, June 08, 2007

You need to call cancel edit on your BindingSource, NOT the object itself.  If that was not in the faq, let me know and I will add it.

Also, there is a bug where depending on what you clicked, the grid does not behave properly.  You can search this forum for that thread.

jeffreyice1 replied on Saturday, June 09, 2007

Thanks, In addtion to that fixing the cancel button how do I tell the object without saving to keep the changes, Because I might bring the object back up then make additional changes that would need to be canceled back to the last keep changes click.

 

For example text field has "Customer Name"

The user changes this to "Customers Real Name" and then clicks keep changes (We do not save we just hide the entry screen.

Then the user wants to make another change and we redisplay the entryscreen an the user changes the filed to "Customers Real" but then desides not to keep the changes.

Instead of going back to "Customers Real Name" it Goes all the way back to "Customer Name".

Thanks

Copyright (c) Marimer LLC