Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ContainerControl.ValidateChildren Method (ValidationConstraints)

Causes all of the child controls within a control that support validation to validate their data.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
[<BrowsableAttribute(false)>]
abstract ValidateChildren : 
        validationConstraints:ValidationConstraints -> bool 
[<BrowsableAttribute(false)>]
override ValidateChildren : 
        validationConstraints:ValidationConstraints -> bool

Parameters

validationConstraints
Type: System.Windows.Forms.ValidationConstraints

Places restrictions on which controls have their Validating event raised.

Return Value

Type: System.Boolean
true if all of the children validated successfully; otherwise, false. If called from the Validating or Validated event handlers, this method will always return false.

ValidateChildren will examine all the children of the current control, causing the Validating event to occur on a control if it meets the criteria spelled out by ValidationConstraints.

You may use several ValidationConstraints parameters at once by combining them with a bitwise OR operator. Combining parameters with a bitwise OR operator will result in a logical AND operation. For example, calling ValidateChildren(ValidationConstraints.ImmediateChildren | ValidationConstraints.Enabled) will only raise the Validating event on controls that are both immediate children of the container AND are enabled.

Regardless of which parameters you specify for this method, a control must have its CausesValidation property set to true in order for its Validating event to occur. You should also set the AutoValidate property of the control or of the control's container to false if you want validation to happen only when you call ValidateChildren, and not when the user shifts focus from the control.

If a control is bound to a data source, and the Validating event occurs, it will cause the control to push its current data back to the data source.

You cannot achieve the opposite effect of a ValidationConstraints parameter by applying a bitwise negation operator. For example, if you supply the negative value of the Visible field to ValidateChildren, it will not validate all children that are not visible on the container. Supplying any negative parameter to ValidateChildren will have no effect on the container or its children.

The following code example will only cause the Validating event to occur for immediate children of the form whose Enabled property is true.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.