Custom Validation of a Child Collection

Custom Validation of a Child Collection

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


mannyk posted on Monday, July 28, 2008

Hi,

I need to be able to validate that at least one item has been added to an Editable Child List.

What is the best way to do this?

 

Lalit replied on Monday, July 28, 2008

Hi,

You may add a custom validation rule for the child collection in your parent object, where you have to check just the count of editable child collection.

 

-Lalit

reagan123 replied on Wednesday, October 08, 2008

I was wanting to do this same type of thing.  I initially added my own validation rule to my parent class to check the count on the child collection.

This rule is set to broken on my dataportal_create when I call CheckRules() which is good.  The only thing is that rule never gets triggered again since there is no property changed method on my child collection.  How can I get the rule to be re-evaluated once I assign a child object to my collection?

Any tips.

Boris replied on Wednesday, October 08, 2008

You overrite the Add method on the collection and trigger the CheckRules for the parent there...

ajj3085 replied on Thursday, October 09, 2008

You can have the parent object listen to the collections ListChanged event.  If you're using a newer version of Csla, you can override OnChildChanged as well.

reagan123 replied on Thursday, October 09, 2008

thanks for the replies guys... I'm going to check out both ideas.

ajj3085... That sounds like the approach i'd like to try, but I have no idea how to implement it.  Any tips or links to how this is done?

I appreciate all of the feedback.

Copyright (c) Marimer LLC