How to validate child collection?

How to validate child collection?

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


tchimev posted on Wednesday, July 01, 2009

I have a base class which inherits BusinessBase.
I have a child property of type BLB in my masterBB.
I need to vlaidate that child collection when items are added or removed.
Errors should be displayed through windows forms error provider.
In my base class I have a fake property(standart .net readonly property) to display errors.
So I add validation rule for the child collection to my fake property.

ValidationRules<MasterBB>.AddRule(ValidateChildCollection, "FakeProperty");

In my base class I hook up for ChildChanged and PropertyChanged events and call

ValidationRules.CheckRules("FakeProperty");

When I change items in the child collection the error provider not seems to refresh correctly.

If masterBB become invalid sometimes error provider does not display the error.
Sometime when masterBB become valid error provider displays previous errors.
After I click on a control the error provider refreshes to correct values.

Is it a good practice to call CheckRules("FakeProperty") in ChildChanged and PropertyChanged events?
Could those calls mess-up the error provider?

tchimev replied on Thursday, July 02, 2009

No one faced that situation?

ajj3085 replied on Thursday, July 02, 2009

Usually I override OnChildChanged, InsertItem, and RemoveItem to call a private method enumerate the collection and call a CheckRules method on each child method, which runs whatever rules need to be run (usually all of them).

Copyright (c) Marimer LLC