Proper Way to Begin/Cancel a Child Collection Edit

Proper Way to Begin/Cancel a Child Collection Edit

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


DivisibleByZero posted on Wednesday, April 08, 2009

Ok I have a Child object that has a Child collection. When I click on a button in my main form it will launch a dialog that will bind to the child collection object. The dialog will have apply and cancel buttons which will need to commit/cancel all changes made to the collection respectively.

My dialog accepts the Children as a parameter:

ChildrenDialog dlg = new ChildrenDialog(child.Children)

I need to know how to properly set up the N level undo for this. I've seen conflicting statements on the forums on how to do this (if you should do it on the object itself or not...or to use the bindingsource).

Can someone please clarify this for me?

Marjon1 replied on Tuesday, April 14, 2009

Sorry I'm not actually contributing to this discussion, but am hopeful to see some responses to this. I need to do the same thing and getting it right from the beginning would be fantastic.

Adalton4 replied on Wednesday, April 15, 2009

Hi,

 

I am also in an almost similar case. I have a root object with a child collection displayed with minimal editable properties in a grid in the main form. For detailed editing, i edit the items in the child collection in a dialog with the same scenario of commit/cancel the changes to the collection (CSLA 3.6.2). I also use a bindingNavigator to navigate and add/delete between the child items, which seems to work great.

 

What i did so far to get the thing (almost) working was

* In the constructor of the dialog

      -> Passing the child collection to the dialog, which seems not to work, it passes the root object

      -> To retrieve the child collection i reassign the datasource to the child collection who i get from drag and drop the collection from the data sources window

public FormBookDetail(BindingSource booksBindingSourceParent)

{

InitializeComponent();

// Set the current item in the parentlist to the current item in the detail pane

booksBindingSource.DataSource = booksBindingSourceParent.DataSource;

booksBindingSource.DataMember = "Books";

booksBindingSource.Position = booksBindingSourceParent.Position;

// Populate the DataSource with the DropDown List data

languageReadOnlyListBindingSource.DataSource = LanguageReadOnlyList.FetchAll();

bookTypeReadOnlyListBindingSource.DataSource = BookTypeReadOnlyList.FetchAll();

bookSubTypeReadOnlyListBindingSource.DataSource = BookSubTypeReadOnlyList.FetchBookType(((Book)booksBindingSource.Current).BookTypeID);

// Set the initial Read Write Control

readWriteAuthorizationBook.ResetControlAuthorization();

}

* In the Closing event of the form

      -> When i press apply, i close the dialog with calling .EndEdit() on the datasource in the dialog to avoid the 'Edit Level Mismatch in AcceptChanges' error when saving in the main form.

private void FormBookDetail_FormClosing(object sender, FormClosingEventArgs e)

{

booksBindingSource.EndEdit();

}

This works while editing 'simple' child collections who rely only on texboxes. However, when i use additional datasources to populate comboxes linked with the child object, it still gives me the 'Edit Level Mismatch in AcceptChanges' error.

 

Copyright (c) Marimer LLC