ValidateChildren not envoking validation on controls with CausesValidation set to false

P

Pavel Dvorak

From my lengthy and painful debugging experiment it seems that
UserControl.ValidateChildren() will not envoke validation of child controls
where their CausesValidation property is false.
I have a rather complex hierarchy starting with a MS CAB SmartPart view
placed on an Infragistics UltraTabPageControl tab, which contains a group
box, a flow panel and finally some UltraComboEditors. When the
ValidateChildren method is run on the view (which inherits from
UserControl), it seems to validate only controls which themselves cause
validation. I implement Validating() event handlers accross the whole
hierarchy, set all CausesValidation to false except the bottom level of
combos where I play with various combinations to see the validation being
triggered.
This dependency seems so odd, because
1 - wasn't ValidateChildren ment exactly a mechanism independent on
(alternative to) auto validation controlled by CausesValidation property.
2 - CausesValidation is supposed to control behaviour of other controls, not
itself.
Am I right about my observation of this schizophrenic character of
CausesValidation, is it something particular to the Infragistics controls
library, or is something wrong in my test case?
Any comments appreciated.
Pavel
 
P

Paul Barbin

Yes, CausesValidation is schizophrenic in that way - it's definitely
confusing. And yes, it seems ValidateChildren was designed to be used
when the controls themselves weren't auto validating. I'm having
almost exactly the same problem. Except with .NET Framework 2.0 I can
set the autovalidation to disable and keep the causesvalidation
property to true. That seems to work perfectly until validation fails
once. When that happens, it seems like it reverts to autovalidation,
I can't leave the control without fixing the problem.

Paul
 
P

Pavel Dvorak

When everything else fails try the documentation:
"If the control can be selected by the user and its CausesValidation
property is true, ValidateChildren will cause the Validating event to
occur.", see
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/CPref17/html/M_System_Windows_Forms_ContainerControl_ValidateChildren.htm
So it's official. I have finally decided I can live with that as this design
still allows me to put my reusable container controls into either auto or
manual validation mode depending on the context.

I am curious to try your situation Paul because there really does not seem
to be the choice of [Prevent|Allow]FocusChange with ValidateChildren. But
setting focus with manual validation is really a different story and each
app can have different requirements although putting focus on the first
invalid control seems to be a good default behaviour.

Regards,
Pavel
 
Top