MaskedTextBox - Overwrite

Editors for WPF Forum

Posted 9 years ago by John Howe
Avatar
Hi Guys,

We are using the MaskedTextBox control to collect a latitude and longitude using the following mask:-

([0-8][0-9]|[9][0])° [0-5][0-9]\.[0-9][0-9][0-9]\'[NS] (1[0-7][0-9]|0[0-9][0-9]|[1][8][0])° [0-5][0-9]\.[0-9][0-9][0-9]\'[EW]

This would work nicely if it were not for the fact that we can find no way of knocking off insert mode and getting the control to go into overwrite mode.

With this sort of mask overwrite mode is more or less essential, just can't find a way of locking the control into this mode. Am I missing something?

Regards

John

Comments (8)

Posted 9 years ago by John Howe
Avatar
Hi Guys,

Little bit of an update.

Found the following code on the web, that works for textbox and textbox based editors:-

PropertyInfo textEditorProperty = typeof(TextBox).GetProperty("TextEditor", BindingFlags.NonPublic | BindingFlags.Instance);
object textEditor = textEditorProperty.GetValue(textBox1, null);

PropertyInfo overtypeModeProperty = textEditor.GetType().GetProperty("_OvertypeMode", BindingFlags.NonPublic | BindingFlags.Instance);
overtypeModeProperty.SetValue(textEditor, true, null);
As expected this does not work for Actipro editors as they appeard to derive from TextBoxBase not TextBox.

I notice that overwrite was requested in May 2009 and was apparently on the TODO list at that time.

I have already looked at replacing the maskedtextbox with a custom parts editor for latitiude and longitude, unfortunatley as this would be built from parts based on TextBoxBase that would not work either.

John
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

The MaskedTextBox does not currently support an overwrite mode. Your best bet is probably to build a custom parts-editor. By default the entry in the parts-editors will select all the text of the next part, so it works much like you'd expect. You can try out the DateTimeEditBox, which allows you to enter each part in sequence without having delete/select text.


Actipro Software Support

Posted 9 years ago by John Howe
Avatar
Hi Guys,

If we were to go the parts based route we would end up using the doubleeditor for the minutes and decimals and that, in common with all your editors, does not have an overwrite mode. Try running your sample browser and then editors/doubleditbox sample. With the deafult value of 1234.56 displayed how would you go about changing the 5 to a 7 (to end up with 1234.76) without highlighting the 5 using the mouse and then hitting the 7 key?

I can see a soloution by having a parts based editor with 17 parts (one for each digit) but that seem a bit 'over the top'

Regards

John
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

No, the parts-based editors leverage the MaskedTextBox. As I mentioned, when moving between parts it selects all the text of the next part. So you can effectively enter an entirely new value, but still have fine grain control to change a single digit.


Actipro Software Support

Posted 9 years ago by John Howe
Avatar
Hi Guys,

We have successfully implemented our geographical position editor using the MaskedTextBox control and one single mask as shown in a previous post. In order for this to work (as it does in competitive products) we had to implement an overwrite mode and disabled the delete and backspace keys.

I am not trying to be impertinent here but I am not sure your implementation of the MaskedTextBox control is quite correct.

The whole point of using a mask is to ensure that characters typed match the mask etc. In order for this to work correctly you can’t allow characters to be inserted or allow the backspace and delete keys to operate. As an example, deleting the first character in your implementation moves all the remaining characters in ‘the string’ left one place and probably invalidates the rest of the string resulting in the loss of data.

We have had a look at a number of competitive implementations and none of these allow text to be inserted or deleted.

I would be grateful for your comments.

Regards

John
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi John,

The Backspace and Delete keys are only allowed if the resulting string does not violate the defined mask. If you have a specific case where that is not true, please send us the steps to reproduce because that would be a bug.

Taking a simple example, assume you have a mask for an email address and currently have the value "some.onee@example.com". In order for the end-user to remove to extra "e", with overwrite mode (assuming that means Delete and Backspace are not allowed as you pointed out above), the end-user would have to completely reenter the entire value. With "insert mode", they could simply delete the extra "e". This greatly reduces the chance of another data entry mistake being made.

Regardless, having an overwrite mode is definitely a feature we'd like to add in the future. But that doesn't mean the "insert mode" isn't another valid mode.


Actipro Software Support

Posted 9 years ago by John Howe
Avatar
Hi Guys,

Accept the point about the ‘ee’ in your example but as requested here’s where it does not work too well.

Create a new WPF application and drop a maskedtextbox on the form and give it a mask of
([0-8][0-9]|[9][0])° [0-5][0-9]\.[0-9][0-9][0-9]\'[NS] (1[0-7][0-9]|0[0-9][0-9]|[1][8][0])° [0-5][0-9]\.[0-9][0-9][0-9]\'[EW]
and set the width so that all characters are visible. Run and enter 123456N12345678W that should result in 12° 34.567'N 123° 45.678'W being displayed. This string is used repeatedly in the following examples.

Move the caret to the first character position and hit the delete key. You will end up with 23° 45.671' significant loss of data.

Clear the control and re-enter the original data.

Now we are going to replace the 123 in the second group with 079. Highlight the 123 and then type 079, you end up with 12° 34.567'n 079° 45. The only way I have found of doing this in the original control is to highlight the 1 type 0, highlight the 2 and type the 7 and then finally highlight the 3 and type the 9

Clear the control and re-enter the original data.

Move the caret to the first character position and hit the 2 key, oops made a mistake should have been the 3 key, hit the backspacein order to enter the 3 and you lose all of the data in the second group and end up with 31° 23.456'

Regards

John
Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Thanks John, we'll look into correctly this for the next maintenance release.


Actipro Software Support

The latest build of this product (v2019.1 build 0683) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.