Skip to content

NumericUpDown Box question(s) #1313

Closed
Closed

Description

@itg-assistant

Harald Bacik asked 2018-01-16 08:36:11 UTC

Hey

I need some clarifications about your NumericUpDown Box

  • When I set the decimal places to 0, I am still able to enter decimal numbers. How can I prevent this?
    The goal is to allow only integers

  • How can I extend the NumericUpDown to show up with some prefix/postfix like currency, percentage or degrees

  • In my database I save my percentage values in format p4, how can I bind the value to show up correct (Saved = 0,2 what should be 20%

  • How can I show up values with it's sign. -> When the value is "1" then it should become "+1,00"?
    In WinForms there was the possibility to set the Format to "+#0,00;-#0,00" then this worked fine

THX for every tip you have for me

Activity

  1. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2018-01-16 17:24:00 UTC

    Just checked in Winforms and I can't see any way to format a NumericUpDown. In Winforms you can also type a decimal value when the Decimals property is set to zero, the result will be a number without decimals, which is correct. Wisej does exactly the same. NumericUpDown cannot be formatted using custom strings in Winforms and in Wisej - the text has to be parsed into a valid number on the client.

    You can format a data bound TextBox control (like in Winforms) and use "p" for percentages or “+#0.00;-#0.00” to show +/-.

    With Wisej you can also attach a javascript event to stop "." or "," from being typed and force only numeric characters.  And you can show a custom +/- button inside the field. You need to create a custom control.

    I attached some sample code you can use and adapt to your requirements.

  2. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Harald Bacik answered 2018-01-21 16:56:31 UTC

    Hey

    First of all: Thx for your solution. I extended it for my needs, but having trouble with a specific behaivour.

    I changed the code from your sample with two little things to show you the problem. Not sure, if it is a bug or not.

    I attached in JavaScript, that when a "wrong" value is inserted, then the whole text should be selected.

    And in code behind: when the control gets entered, then also the whole text should be selected.

    Now, when I enter the textbox, everything gets selected as expected. When the first input is a "wrong" (e.g. "a") and then a correct value is used, then it get's attached at the end and not overwritten:

    The starting value = 0,00

    When I enter a wrong and then 1 it becomes => 0,001 and it does not overwrite the 0,00 to => 1 as expected.

    Could you please check, if this is a bug or a problem by my code!?

    THX a lot - Have a nice start of the week

    Harald

  3. itg-assistant commented on Jun 12, 2026

    @itg-assistant
    Author

    Luca answered 2018-01-22 23:43:48 UTC

    The javascript code you attached calls select() when a valid digit is typed:

    if ('+-1234567890'.indexOf(key) == -1)
        e.stop();  <--- this is when an invalid digit is pressed.
    else
        this.select();   <--- select() is not a valid function. "this" is a widget not an element.
    

    should be:

    if ('+-1234567890'.indexOf(key) == -1){
        e.stop();
        this.selectAllText();
     }
    
    HTH
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions