Binding Source EndEdit calls Dataportal_Update

Binding Source EndEdit calls Dataportal_Update

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


billa1972 posted on Thursday, November 09, 2006

Hi,

First, I have an EditableRootCollection of users.  I show that on a readonly grid and when i double click a row a modal form opens up to edit the specific user.

i think have read all the correct ways to save if you are using windows data binding...IE: apply changes via the binding source object.  But when i call EndEdit, and i have a break point on my user dataportal_update method, and that get's called...This is before i hit the clone line of code.

Any one else experiencing this?  Am i doing this correctly with EditRootCollection?

Thanks for any help

Private Sub Save()

bindingSource.RaiseListChangedEvents = False
bindingSource.EndEdit()  <- - this calls the Save on the object, and thus the dataportal_update method

Dim temp As User = mUser.Clone

Try

mUser = temp.Save

Catch ex As Exception

Throw

Finally

bindingSource.RaiseListChangedEvents = True
bindingSource.ResetBindings(False)

End Try

End Sub

billa1972 replied on Thursday, November 09, 2006

Update:

Ok, after stepping through the code, this is what happens:

1) When you call EndEdit on binding source, that ends up calling AcceptChangesComplete on the businessbase (core)

2) This ends up doing a check to see if parent is something and if so calls parent.ApplyEditChild. 

3) So if parent is EditableRootListBase, then SaveItem is called from ApplyEditChild. 

4) SaveItem calls this code: Me.Item(index) = DirectCast(item.Save, T).  Note the Save. This calls dataportal_update.

So, the question is:  Am I doing this correctly?  How should I present the EditableRootListBase collection in the UI?  Or should I?

Thanks again.

ajj3085 replied on Thursday, November 09, 2006

That behavior is pretty much by design.  If you don't want it, subclasss BusinessListBase.

Bayu replied on Thursday, November 09, 2006

Hey billa1972,

Unfortunately I don't have a EditableRootList in my current project, but the following is the save routine that is inherited by all my views:


    Protected Overridable Function SaveObject(ByVal rebind As Boolean) As Boolean

        Me.View.SuspendEvents()

        Dim success As Boolean = False
        Dim temp As TObject = Me.BusinessObject.Clone
        temp.ApplyEdit()
        Try
            Me._BusinessObject = temp.Save
            If rebind Then
                Me.View.Rebind()
            End If
            success = True

        Catch ex As Csla.DataPortalException
            MessageBox.Show(ex.BusinessException.ToString, _
              "Error saving", MessageBoxButtons.OK, _
              MessageBoxIcon.Exclamation)

        Catch ex As Exception
            MessageBox.Show(ex.ToString, _
              "Error saving", MessageBoxButtons.OK, _
              MessageBoxIcon.Exclamation)

        Finally
            Me.View.ResumeEvents()

        End Try

        Return success

    End Function



Notice that I apply the edit _on the clone_, in contrast to your snippet where you apply the edit (EndEdit) on the bindingsource. I really have no clue if this would resolve your issue, but in a way it looks just as if it might.

Regards,
Bayu

Copyright (c) Marimer LLC