Negative sign at the end

4 posts, 0 answers
  1. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 30 Sep Link to this post

    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.

  2. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 03 Oct Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Patrick
    Patrick avatar
    372 posts
    Member since:
    Aug 2012

    Posted 04 Oct Link to this post

    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?

  5. Dinko
    Admin
    Dinko avatar
    204 posts

    Posted 06 Oct Link to this post

    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.
Back to Top