The requested page is not available for the requested platform. You are viewing the content for Default platform.

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.v19.1.dll

Declaration

public static event EventHandler<CustomNeedToValidateRuleEventArgs> CustomNeedToValidateRule
Public Shared Event CustomNeedToValidateRule As EventHandler(Of CustomNeedToValidateRuleEventArgs)

Event Data

The CustomNeedToValidateRule event handler receives an argument of the CustomNeedToValidateRuleEventArgs type. 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

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() {
        InitializeComponent();
    }
    protected override void OnActivated() {
        base.OnActivated();
        DevExpress.Persistent.Validation.RuleSet.CustomNeedToValidateRule += RuleSet_CustomNeedToValidateRule;
    }
    protected override void OnDeactivated() {
        DevExpress.Persistent.Validation.RuleSet.CustomNeedToValidateRule -= RuleSet_CustomNeedToValidateRule;
        base.OnDeactivated();
    }
    void RuleSet_CustomNeedToValidateRule(object sender, CustomNeedToValidateRuleEventArgs e) {
        e.NeedToValidateRule = !(e.Rule.Id == "MyRule");
        e.Handled = !e.NeedToValidateRule;
    }
}
See Also