0
votes

I'm doing the following to a TextEdit which is on a dialog form with a save and cancel button.

_underlyingEditor.Properties.Mask.EditMask = @"\((\d{3})\)-(\d{3})-(\d{4})";
_underlyingEditor.Properties.Mask.MaskType = MaskType.RegEx;
_underlyingEditor.Properties.Mask.UseMaskAsDisplayFormat = true;
_underlyingEditor.Properties.AutoHeight = false;

The problem is that if the user types a bad value into the editor then clicks Cancel the validation error shows and the screen doesn't close. I've tried tying into the cancel buttons click event to try to clear the value from the editor but it's not firing.

Has anyone figured out a way to handle this?

2

2 Answers

0
votes

Handle the FormClosing event and set the e.Cancel parameter to False. This should help. The e.CloseReason parameter provides information about the reason of closing. You cah check it if it is necessary.

0
votes

The dialog can't be closed if validation failed, this is a standard behavior and isn't related on DevExpress controls. However, you can workaround it by using DXErrorProvider to display these errors. This allows the form to be closed in spite of incorrect data. Please handle the editor's Validating event as shown below:

void textEdit1_Validating(object sender, System.ComponentModel.CancelEventArgs e) {
    if(e.Cancel) {
        dxErrorProvider1.SetError(textEdit1, "Error");
        e.Cancel = false;
    }
    else dxErrorProvider1.SetError(textEdit1, null);
}

Note, that you can use the DXErrorProvider.HasErrors property within the FormClosing event to avoid a form closing if it nesessary.