How do you update parent error text to show child error text?

How do you update parent error text to show child error text?

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


mike1j1 posted on Wednesday, July 29, 2009

I have a class where there are a number of business rules in an object, and the object has a child that also has business rules.  The object is in a grid, and the child contains obscure rules that aren't changed very often, so they aren't show in the grid for space reasons.  However, occasionally the user will change the child settings - and I want the validity/errors from those changes to be reflected in the grid.

I added this method:

        public static bool ValidChild(object target, RuleArgs e)
        {
            BusinessBase businessObject = (BusinessBase)Utilities.CallByName(
                target,
                e.PropertyName,
                CallType.Get);

            if (!businessObject.IsValid)
            {
                e.Description = string.Format(
                    Resources.InvalidChild,
                    e.PropertyFriendlyName,
                    businessObject.BrokenRulesCollection.ToString());

            }

            return businessObject.IsValid;
        }

and added a business rule to validate the child.  This works fine if the child is invalid initially.  However, if the child is changed so that the validity of any of its fields change, the changes in the child's broken rules collection are not percolating up to the parent.

What can I do to make the parent correctly reflect the current error state of the child (not just IsValid, but the text from the broken rules)?

JonnyBee replied on Monday, August 03, 2009

Hi,

The error info is retrieved through the IDataErrorProvider interface (that is implemented in BusinessBase).

You could probably override the IDataErrorProvider.Error property in your parent object to retrieve error messages from parent and child object. This property is called in databinding to show the RowError in your datagridviews RowHeader.

/jonnybee

Copyright (c) Marimer LLC