Validating A Collection

Validating A Collection

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


JZuerlein posted on Thursday, March 22, 2007

I have a situation where I have a Person object with a collection of memberships to groups.

I need a business rule that says a person can be a member of the "Employees" group or the "Retired Employees" group, but not at the same time.  I've got that working for the most part.  The problem comes into play when both membership child objects have broken rules, and the user modifies one of them and it is valid.  When this happens, I need to run the validation check for both rows, so they both become valid.

I think what I need is an event on BrokenRulesCollection to tell me when the number of broken rules has changed.  That way I could run some code to call check

For now my solution is to raise an event in the membership object, and have the handler in the collection object iterate over the children and check rules.

Anyone have a better idea?

Public Property ChildID() As Integer

Get

CanReadProperty("ChildID", True)

Return _childID

End Get

Set(ByVal value As Integer)

CanWriteProperty("ChildID", True)

If Not _childID.Equals(value) Then

_childID = value

Dim c As Integer = Me.BrokenRulesCollection.Count

ValidationRules.CheckRules("RelationshipTypeID")

PropertyHasChanged("ChildID")

If (Me.BrokenRulesCollection.Count <> c) Then RaiseEvent CheckedRulesNeeded(Me, New EventArgs())

End If

End Set

End Property

xal replied on Thursday, March 22, 2007

Have you tried handling BrokenRulesCollection.ListChanged event?

Andrés

Copyright (c) Marimer LLC