Benjamin Basmaci
Benjamin Basmaci

Reputation: 2557

Devexpress RegEx Mask with different Displayformat doesn't work

I have a Textedit Control that I want to behave in a certain way:

When the Control has input focus, I want to only allow the input of positive whole Numbers (not zero). I achieve that by using Properties.Mask, which works fine.

When the Control does NOT have input focus, I want it to Display the entered number but with ",00" at the end.

So basically, while I enter something, I only see what I enter e.g. "17" but when the Control loses focus, I want it to show "17,00". So that I am only allowed to enter whole positive numbers but the Control will always add ",00" afterwards.


My understanding is that there are basically two different "modes": DisplayMode and EditMode.

EditMode = The Control has focus.

DisplayMode = The Control does not have focus.

In EditMode, I can type things into my Textedit Control. What I can and can not enter is determined by the Mask.

When I lose focus, it goes into DisplayMode. Here I cant type anything into the TextEdit but now the displayed text is not determined by the mask any more but by the Property "Properties.DisplayFormat". So to achieve my goal, I tried to set the DisplayFormat.FormatString to "0.00", so that it would always show two decimal places "x,00".

Somehow, this doesn't work as expected. The DisplayFormat doesn't seem to do anything and even in DisplayMode, the TextEdit still shows just the whole number without the decimal places.

Those are the entered properties

I realize that I could use events to work around this problem but I think that's what DisplayFormat, EditFormat and Mask are for and I really don't want to handle multiple events for something that small.

Upvotes: 0

Views: 2898

Answers (2)

Benjamin Basmaci
Benjamin Basmaci

Reputation: 2557

To accomplish the above is fairly simple:

To only allow positive whole numbers, you need to set the MaskType to Numeric and use the EditMask ##########;. The number of # represents the possible number of didgets so ten times # means you can use a ten-digit number. (see nempoBu4's answer)

To show an additional ,00 when the control loses the focus, you simply need to set the DisplayFormat as FormatType = Numeric and FormatString = n2.

Upvotes: 0

nempoBu4
nempoBu4

Reputation: 6621

Accodring to DevExpress Knowledge Base topic DisplayFormat is not working in unbound mode.

Problems with formatting occurs because an unbound text editor stores a value as a string, therefore formatting cannot be applied.

If you use XtraEditors 3 or higher, you may wish to set the editor's Mask.MaskType property to Numeric. In this case, the editor is forced to handle the edit value as a number and, therefore, it can format it.

If you wish not to use the Numeric (or DateTime) mask, please use the ParseEditValue event to convert a string to a number.

I can suggest you to use Numeric mask with n0 as edit mask:
Numeric mask

Upvotes: 1

Related Questions