Leading zeros in RadNumericUpDown

2 posts, 1 answers
  1. Markus
    Markus avatar
    2 posts
    Member since:
    Mar 2018

    Posted 14 Jun 2018 Link to this post

    Hi,

    I would like to use the RadNumericUpDown but would have to make all numbers double digits.

    So with numbers from 1 to 99 there should 01, 02, 03 ... appear.

    Is there a function for this?

     

    Thanks in advance

  2. Answer
    Kalin
    Admin
    Kalin avatar
    1352 posts

    Posted 19 Jun 2018 Link to this post

    Hello Markus,

    What I can suggest you would be to inherit from RadNumericUpDown and override the FormatEdit and FormatDisplay method. They are responsible for formatting the text when in edit and in display mode. Please try the following snippets:

    public override string FormatDisplay()
    {
        if (this.Value.HasValue)
        {
            return this.Value.Value.ToString("00");                
        }
     
        return base.FormatDisplay();
    }
     
    public override string FormatEdit()
    {
        if (this.Value.HasValue)
        {
            return this.Value.Value.ToString("00");
        }
     
        return base.FormatEdit();
    }

    Hope this helps. Please let me know if you have any other questions or concerns.

    Regards,
    Kalin
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top