MaskedTextBox deletes entire string on keyboard press at front

Editors for WPF Forum

Posted 6 years ago by Brian Pratt
Version: 17.2.0664

Steps to reproduce:

1) Open the Actipro Software WPF Controls Sample Browsesr application

2) Go to Editors > Masked Text Box

3) Enter this as a mask: 


 4) Enter "NaN,1234" into the top text box (with the "Text matches mask" checkbox)

5) Place your cursor at the beginning of the text box (next to the first "N" in "NaN")

6) Hit the delete key

7) Expected: "NaN" is deleted leaving the ",1234"

8) Actual: Everything is deleted but the comma, leaving "," in the text box


Is there a way to stop this from happening?  I want to be able to edit the first number while leaving the second number.  (the PointEdit does not work in my case because you recently removed the "AllowNaN" feature).


More Info: if I use a single character placeholder instead of NaN, it seems to work correctly.

Doesnt work

[NaN, 1234]

 does work





[Modified 6 years ago]

Comments (3)

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Brian,

I'd probably recommend this pattern instead:  (\d+|NaN),(NaN|\d+)

But note it's still going to happen like above because it's running through the regular expression looking for a match.  In your case, after the delete the text is "aN,1234" which is not valid so the rest of it is cleared.

You can select the "NaN" text and type a number there without having the rest clear since that still adheres to the regex pattern.  It's not as ideal as being able to delete the NaN text one character at a time.  However there's no real good way to support that with this control without breaking other things.

In regards to the other PointEditBox issue, we can continue discussion on that in the related forum thread.

Actipro Software Support

Posted 6 years ago by Brian Pratt

Thanks for your help and suggestions.

We went with using one character (  *  ) instead of NaN (which was not very user friendly anyway).  So I think we are good for now.

Just a thought, the editor automatically adds the text "NaN" to the textbox when you type the letter N, so it is doing some sort of look-ahead or auto-fill already.  Could it detect delete the same way?  (look ahead for one of the regex options).



Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Brian,

The look-ahead works since it's matching everything in the regex up to that point and then if it sees literal text in the pattern right after the current input match, it auto-fills in the literals.  When deleting in this case, the regex is immediately invalid at the start so we don't know how to back things out in the same way.

Using a single character is probably better, and we'll see what we can do to help with PointEditBox.

Actipro Software Support

The latest build of this product (v24.1.2) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.