Skip to main content
All docs
V25.1
  • .NET 8.0+

    RuleSet.ValidateAll(IObjectSpace, IEnumerable, ContextIdentifiers, ValidationFailedDelegate, Frame) Method

    Validates multiple objects against RuleSet‘s rules with the given validation contexts, returns a result and throws a ValidationException if the validation fails.

    Namespace: DevExpress.Persistent.Validation

    Assembly: DevExpress.Persistent.Base.v25.1.dll

    Declaration

    public bool ValidateAll(
        IObjectSpace targetObjectSpace,
        IEnumerable targets,
        ContextIdentifiers contextIDs,
        ValidationFailedDelegate validationFailedDelegate,
        Frame sourceFrame = null
    )

    Parameters

    Name Type Description
    targetObjectSpace IObjectSpace

    An IObjectSpace used by a validation target.

    targets IEnumerable

    The list of objects to check.

    contextIDs ContextIdentifiers

    The ContextIdentifiers object which is a set of validation contexts, rules for which will be collected. Default contexts are stored in the DefaultContexts enumeration.

    validationFailedDelegate DevExpress.Persistent.Validation.ValidationFailedDelegate

    A method to call if the validation fails.

    Optional Parameters

    Name Type Default Description
    sourceFrame Frame null

    The Frame of the Controller that validates objects. This parameter is optional and used in WinForms applications only.

    Returns

    Type Description
    Boolean

    true, if validation passes; otherwise, false.

    Remarks

    This method raises the RuleSet.RuleValidated event for each target and the RuleSet.ValidationCompleted event at the end of validation.

    The following example demonstrates how to use this method to validate objects when an Action is executed:

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.Actions;
    using DevExpress.Persistent.Base;
    using DevExpress.Persistent.Validation;
    // ...
    public partial class CustomValidationController : ViewController {
        public CustomValidationController() {
            SimpleAction validationAction = new SimpleAction(this, "ValidateBeforeSave", PredefinedCategory.Edit);
            validationAction.Execute += ValidationAction_Execute;
        }
        private void ValidationAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
            Validator.RuleSet.ValidateAll(ObjectSpace, ObjectSpace.GetObjectsToSave(false), DefaultContexts.Save, null, Frame);
        }
    }
    
    See Also