Skip to main content
A newer version of this page is available. .
All docs
V22.1

CustomTextMaskInputArgs.Cancel() Method

Cancels an edit a user attempts to perform.

Namespace: DevExpress.Data.Mask

Assembly: DevExpress.Data.v22.1.dll

NuGet Package: DevExpress.Data

Declaration

public void Cancel()

Remarks

The Cancel method cannot be called if the ActionType returns “Init”.

The code sample below illustrates how to limit the maximum number of characters to 5.

protected override void ProcessCustomTextMaskInput(CustomTextMaskInputArgs args) {
    if (args.IsCanceled || args.ResultEditText.Length < args.CurrentEditText.Length ||
        args.ActionType == CustomTextMaskInputAction.Init || args.ResultEditText.Length <= 5)
        return;
    if (args.CurrentEditText.Length == 5 && args.CurrentSelectedText == String.Empty) {
        args.Cancel();
        return;
    }
    var maxInsertLength = 5 - args.CurrentHead.Length - args.CurrentTail.Length;
    args.SetResult(args.CurrentHead + args.InsertedText.Substring(0, maxInsertLength), args.CurrentTail);
}
See Also