This is a migrated thread and some comments may be shown as answers.

Negative sign at the end

3 Answers 162 Views
NumericUpDown
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Patrick asked on 30 Sep 2016, 08:30 AM

Hello,

is it possible to accept that the negative sign is put at the end of the number, when editing?

For example: typing "55-" will enter "-55" and will be formatted correctly when the cursor leaves the control.

3 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 03 Oct 2016, 07:10 AM
Hello Patrick,

The desired by you functionality is not supported by RadNumericUpDown with its current implementation.

What we could suggest you is to consider using RadMaskedNumericInput  - it places the sign as expected while typing a number. So, when "55" is entered and after that "-" the input will be formatted as expected.

Hope this helps.

Regards,
Nasko
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
answered on 04 Oct 2016, 05:06 AM

Hello Nasko,

I've just tried the RadNumericUpDown control, but I have problems with it.

The XAML code I'm using is the following:

<tk:RadMaskedNumericInput Value="-12345.67"
                                                              FormatString="#,###.00"
                                                               IsClearButtonVisible="False"
                         Mask=""
                         SelectionOnFocus="DefaultSelectAll"
                                         SpinMode="None"
                                                              maskedInput:MaskedInputExtensions.AllowMinusOnNullValue="True" />

If the control contains already a negative value (say "-1"), I enter it with a tab (the text is selected) and type "-2", the control displays "2".
If it contains "1" at the beginning, doing the same thing shows "-2".
This is completely counter-intuitive and leads to errors when entering values: if the old and new value are negative, I must enter a "-", but only after the first digit; if the old value is positive and the new one is negative, I can enter a "-" anywhere; if the new value is positive, never enter the "-".

Is it a bug in the control or something wrong with with properties?

0
Dinko | Tech Support Engineer
Telerik team
answered on 06 Oct 2016, 11:21 AM
Hello Patrick,

The minus sign on the keyboard toggles the value from negative to positive and vice versa, regarding the caret position. If you want to clear the mask when its value is select all and the minus key is pressed you can override the HandleSubtractkey method of RadMaskedNumericInput.
public class NumericInputMinusClearsSelection : RadMaskedNumericInput
    {
        protected override bool HandleSubstractKey()
        {
            // Show Negative symnbol when all is selected.
            if (!string.IsNullOrEmpty(this.Text) && this.Text.Length == this.SelectionLength)
            {
                if (this.ClearCommand != null)
                {
                    this.ClearCommand.Execute(null);               
                }
 
                this.ToggleNegativeSignKey();
                return true;
            }
 
            return base.HandleSubstractKey();
        }
    }

We have SDK example in our GitHub repository showing the mentioned above approach. Give this project a try and let us know if it works for you.

Regards,
Dinko
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
NumericUpDown
Asked by
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Nasko
Telerik team
Patrick
Top achievements
Rank 2
Iron
Iron
Iron
Dinko | Tech Support Engineer
Telerik team
Share this question
or