Save using CslaActionExtender stops subsequent raise of ListChanged event

Save using CslaActionExtender stops subsequent raise of ListChanged event

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


Topher posted on Tuesday, May 12, 2009

Windows form using Csla version 3.6.2-090322.

I have an editable root object which contains an editable child collection. If I add an item to the child collection before I save using the CslaActionExtender control, everything works as expected. Once I save, the datagridview my child collection is bound to no longer displays any new items and the ListChanged event on the binding source my child collection is bound to stops firing. The new items are added to the child collection though.

Should I be manually raising some sort of event when I add items to the collection so the datagridview displays the newly added item?

I'm adding the new item to my child collection using the following code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
_rootObject.ChildCollection.AddChild()
End Sub

The AddChild method looks like this:
Public Sub AddChild()
Me.Add(Child.NewChild())
End Sub

The NewChild method is a factory method which calls DataPortal.CreateChild(Of Child), which then calls an Overload of Child_Create() so I can load a few default values.

RockfordLhotka replied on Tuesday, May 12, 2009

You might need to force a ListChanged event?

You might also consider using the pre-existing AddNew() capability rather than inventing one.

Override AddNewCore() in your collection, and then call the AddNew() method on the collection to trigger it. The code is similar to what you are doing now, but fits directly into the pre-defined .NET collection model.

Topher replied on Wednesday, May 13, 2009

Thanks a ton Rocky! That worked great and once you mentioned AddNewCore, I looked it up in your business objects book and sure enough, there it was :)

By the way, I just started working with the framework and it's fantastic! Thanks for all your effort.

Copyright (c) Marimer LLC