Problems with edit levels when data binding DynamicRootList and child screen.

Problems with edit levels when data binding DynamicRootList and child screen.

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


breiec posted on Monday, February 23, 2009

Using CSLA Version 3.6.1

I am having problems with edit levels when data binding a DynamicRootList to a grid. Then from the grid I open screen with the child collection. For example.

I have the following objects.
AdhesiveTypes (DynamicRootList)
AdhesiveType (DynamicRoot)
AdhesiveTypeCategories (EditableChildList)
AdhesiveTypeCategory (EditableChild)

I have a Windows form that has a grid of AdhesiveTypes and when a user clicks on a link in the grid I am opening a new edit window that displays a list of AdhesiveTypeCategories. When opening the edit window I am passing in the AdhesiveType to the constructor of the form and then calling the BeginEdit() on it and then set it to the binding source. This form has two datasources, one for AdhesiveType and another for AdhesiveTypeCategories. However, editing only occurs on AdhesiveTypeCategories on this form.

When the user makes change and then click a cancel button I am calling the mAdhesive.CancelEdit() and closing the form. Problem is that the CancelEdit seems not to work. The edit level doesn't rollback. When the form loads the edit level is at 1, when begin edit is called it goes to 2, when cancel is called, it stays at 2.

Here is the pertinent code on the parent grid:

Private Sub EditCategories(ByVal adhesiveId As Integer)

        Dim adhesiveType As AdhesiveType = mAdhesiveTypes.GetItem(adhesiveId)

        Dim categoriesEditForm As New SelectCategoriesListForm(adhesiveType)
        categoriesEditForm.ShowDialog()
End Sub

Then on the child screen:

Public Sub New(ByRef adhesive As AdhesiveType)
        InitializeComponent()
        mAdhesive = adhesive

        mAdhesive.BeginEdit()
        AdhesiveBindingSource.DataSource = mAdhesive
End Sub

The cancel looks like this:

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click

        CategoriesBindingSource.RaiseListChangedEvents = False
        AdhesiveBindingSource.RaiseListChangedEvents = False

        BindingHelper.UnbindBindingSource(CategoriesBindingSource, False, False)
        BindingHelper.UnbindBindingSource(AdhesiveBindingSource, False, True)

        CategoriesBindingSource.DataSource = AdhesiveBindingSource

        mAdhesive.CancelEdit()

        CategoriesBindingSource.RaiseListChangedEvents = True
        AdhesiveBindingSource.RaiseListChangedEvents = True

        Me.Close()

    End Sub

Note that if instead of passing in the item from the bound dynamic root list, I declare a local instance of the list and then pass the item to the child form it works correctly. I am guessing it has something to do with passing in the root item that is bound, but that is just a guess at this point. Any pointers on how to handle this scenario?

Copyright (c) Marimer LLC