.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.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.v21.1.dll


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.


By default, a rule is validated when it corresponds the current context. Handle this event to change this behavior. Set the NeedToValidateObjectEventArgs.NeedToValidate parameter to false to cancel the validation, or set it to true to enable the validation. Set the Handled parameter to true to cancel the default logic that determines whether a rule should be validated. The code below demonstrates how to disable a particular rule by its IRule.Id property using the controller.

public partial class RuleDisableController : ViewController {
    public RuleDisableController() {
    protected override void OnActivated() {
        DevExpress.Persistent.Validation.RuleSet.CustomNeedToValidateRule += RuleSet_CustomNeedToValidateRule;
    protected override void OnDeactivated() {
        DevExpress.Persistent.Validation.RuleSet.CustomNeedToValidateRule -= RuleSet_CustomNeedToValidateRule;
    void RuleSet_CustomNeedToValidateRule(object sender, CustomNeedToValidateRuleEventArgs e) {
        e.NeedToValidateRule = !(e.Rule.Id == "MyRule");
        e.Handled = !e.NeedToValidateRule;
See Also