Dynamic Root List - Editable Root's Editable Child List not saving via DataGridView

Dynamic Root List - Editable Root's Editable Child List not saving via DataGridView

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


simpleman posted on Friday, February 28, 2014

Hi,

I’m developing a Winforms app using .NET 4.5 and CSLA 4.5.

I’ve have a Dynamic Root List that has Editable Root objects with an Editable Child list.

I’ve have two DataGridViews bound to the same binding source with the second DataGridView’s data member set to the child list.

Selecting an Editable Root from Grid 1 displays the children as expected in Grid two.  Inserting child records or updating existing child records in Grid 2 only seem to persist when I select a different Editable Root from Grid 1.

If I refresh the Dynamic Root List before selecting a different Editable Root the amendments to the child records are lost.

If I add a new Editable Root and Editable Children refreshing the Dynamic Root List will persist the Editable Root but not the children, they just disappear.

Calling EndEdit on the grids before refreshing the Dynamic Root List doesn’t change the result.  Creating a separate binding source for Grid 2 and binding that to the first binding source made no difference either.

If I call SaveItem from the Dynamic Root List it will save the children, however I was hoping not to have to manually do that.

Do you have any suggestions as to why the Editable Child list is not saving when the Editable Root does?

Your help is greatly appreciated.

Kind regards

 

Nathan

tiago replied on Sunday, April 27, 2014

Hi Nathan,

Dynamic Root List is a stereotype that intends to support the UI control DataGridView (Windows Forms) or DataGrid (WPF). While using an Editable Root, you must explicitly call Save on the object, usually when you click the UI SAVE button. When you use a Dynamic Root List, you don't have (or need) a SAVE button, as each object is saved when you move to another line of your DataGridView.

simpleman
Selecting an Editable Root from Grid 1 displays the children as expected in Grid two.  Inserting child records or updating existing child records in Grid 2 only seem to persist when I select a different Editable Root from Grid 1.

You are using Dynamic Root List on a scenario that is more complex than it is supposed to be. DRL supports data editon on one DataGridView. You are using two DataGridView with a master/detail relation (kind of). Even so the behaviour you describe is what Dynamic Root List is supposed to do. 

To put it simple and clear, a Dynamic Root object shouldn't have children. If your Dynamic Root objects need to have children, then you must handle the object's Save when you edit the children.

Then again, if you need to handle object's Save, why use a Dynamic Root List at all? An Editable Root List seems more suited to your scenario...

Copyright (c) Marimer LLC