Skip to main content
.NET 8.0+

RuleSet.CustomNeedToValidateRule Event

Occurs when the validation system determines whether or not a rule should be validated.

Namespace: DevExpress.Persistent.Validation

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

Declaration

public static event EventHandler<CustomNeedToValidateRuleEventArgs> CustomNeedToValidateRule

Event Data

The CustomNeedToValidateRule event's data class is CustomNeedToValidateRuleEventArgs. The following properties provide information specific to this event:

Property Description
ContextId A validation context of the rule.
Handled Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing. Inherited from HandledEventArgs.
NeedToValidateRule Specifies whether the rule will be validated or not.
ObjectSpace An Object Space of a validation target.
Reason The reason for performing or rejecting the validation.
Rule A rule to be checked on a CustomNeedToValidateRuleEventArgs.Target.
Target A target object of validation.

Remarks

The validation system validates a rule when it corresponds to the current context. Handle this event to change this behavior. The NeedToValidateObjectEventArgs.NeedToValidate parameter allows you to cancel or enable the rule validation. Set the Handled parameter to true to cancel the default logic that determines whether a rule should be validated.

The following Controller unconditionally enables the rule with Id = “MyRule” for the Employee Detail View:

using DevExpress.ExpressApp;
using DevExpress.Persistent.Validation;
// ...
namespace MySolution.Module.Controllers {
    public class ValidateMyRuleAlwaysController : ObjectViewController<DetailView, Employee> {
        protected override void OnActivated() {
            base.OnActivated();
            RuleSet.CustomNeedToValidateRule += RuleSet_CustomNeedToValidateRule;
        }
        void RuleSet_CustomNeedToValidateRule(object sender, CustomNeedToValidateRuleEventArgs e) {
            if (!e.Handled && e.Rule.Id == "MyRule") {
                e.NeedToValidateRule = true;
                e.Handled = true;
            }
        }
        protected override void OnDeactivated() {
            RuleSet.CustomNeedToValidateRule -= RuleSet_CustomNeedToValidateRule;
            base.OnDeactivated();
        }
    }
}

If you want to enable this rule for all Views in the application, subscribe to this event in the ModuleBase.Setup method.

See Also