Skip to main content
All docs
V24.2
.NET 8.0+

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

Validates multiple objects against RuleSet rules with the given validation contexts. If validation fails, the ValidationException is thrown and the method passed as the validationFailedDelegate parameter is called.

Namespace: DevExpress.Persistent.Validation

Assembly: DevExpress.Persistent.Base.v24.2.dll

Declaration

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 for which rules 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 IRuleSet.ValidationCompleted event at the end of validation.

The following code snippet 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.GetService(Application.ServiceProvider)
            .ValidateAll(ObjectSpace, ObjectSpace.GetObjectsToSave(false), DefaultContexts.Save, null, Frame);
    }
}
See Also