Child Collection validation and ErrorProvider

Child Collection validation and ErrorProvider

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


razorkai posted on Monday, July 31, 2006

Hi folks.

I've just come across an issue I can't quite figure out.  I have an object with a child collection, and I have created a custom Rule to make sure the object is not saveable unless it has at least one child in the child collection.  I used the ListChanged event of the parent's child collection property to fire the ValidationRules.CheckRules method (got this from another post) when a child is added or removed and that all works great.  If I remove all children from the collection the object becomes invalid and I can't save it. 

The problem is that I want to use the error provider to display the error next to the ListBox that I have bound to the child collection.  The trouble with this is that binding to a child collection creates a second bindingsource.  You link the error provider to a binding source, but if I link it to the parent it doesn't know which control to display the error icon against, and if I link to the child collection binding source it doesn't know there is an error - preumably because the validation is on the parent object?  Is there a way to achieve what I want and have the error provider correctly show this error next to my listbox?  Hope this makes sense.

TIA

John.

Copyright (c) Marimer LLC