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.v24.2.dll
NuGet Package: DevExpress.Persistent.Base
#Declaration
public bool ValidateAll(
IObjectSpace targetObjectSpace,
IEnumerable targets,
ContextIdentifiers contextIDs,
ValidationFailedDelegate validationFailedDelegate,
Frame sourceFrame = null
)
#Parameters
Name | Type | Description |
---|---|---|
target |
IObject |
An IObject |
targets | IEnumerable | The list of objects to check. |
context |
Context |
The Context |
validation |
DevExpress. |
A method to call if the validation fails. |
#Optional Parameters
Name | Type | Default | Description |
---|---|---|---|
source |
Frame | null | The Frame of the Controller that validates objects. This parameter is optional and used in Win |
#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);
}
}