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
NuGet Package: DevExpress.Persistent.Base
#Declaration
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 |
|
#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);
}
}