Saving/Cancelling child records

Saving/Cancelling child records

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


Tommybouy posted on Monday, August 13, 2007

I created a property called IsBrandNew (as suggested in a post) that is true on the creation of a child object and is set to false after the first applyedit is called. I use the addnew method on my collection object that adds the new object to the collection the passes it to a form. This way on the first use of the new child object if they cancel I remove the object from the collection. The problem is, if the user saves the object I set the flag to false then finish the applyedit. If the user calls up the same object again and cancels for some reason the IsBrandNew flag is true and the object is removed from the collection.

I have my own baseobjects that inherit from CSLA objects and it is in this businessbase object that I have declared my isbrandnew variable and property and also have overriden the Apply and Cancel methods to deal with the collections.

Friend Property IsBrandNew() As Boolean

   Get

      Return bIsBrandNew

   End Get

   Set(ByVal value As Boolean)

      bIsBrandNew = value

   End Set

End Property

Public Shadows Sub ApplyEdit()

   If Me.IsNew AndAlso Me.IsChild And Me.IsBrandNew Then

      Try

         Me.IsBrandNew = False

      Catch ex As Exception

         ' if we are here then probably the child had no parent object

      End Try

   End If

   MyBase.ApplyEdit()

End Sub

Public Shadows Sub CancelEdit()

   Try

      If Me.IsChild = True AndAlso Me.IsNew = True AndAlso Me.IsBrandNew = True Then

         Me.Parent.remove(Me)

      End If

   Catch ex As Exception

   End Try

   MyBase.CancelEdit()

End Sub

Hopefully someone can see what I am doing wrong.

Thanks

 

ajj3085 replied on Tuesday, August 14, 2007

Are you marked bIsBrandNew as NotUndoable?

Copyright (c) Marimer LLC