Positive Currency Values In WPF Telerik RadMaskTextBox Of Currency Mask

4 posts, 0 answers
  1. Vishal
    Vishal avatar
    16 posts
    Member since:
    Jan 2011

    Posted 26 Feb 2011 Link to this post

    Hello,

    I am using a WPF Telerik RadMaskTextBox of Currency Mask in my application, but the problem is that I am able to enter negative currencies in this radmasktextbox. Is there a way, such that we can restrict the user to enter only positive values? If so, how?

    Thanx.

  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 01 Mar 2011 Link to this post

    Hi Vishal,

    Yes, this is possible. You can handle the ValueChanging event of the RadMaskedTextBox and cancel it (e.Handled=true) if the new value is less than 0. This will revert the value back to the old one.

    Kind regards,
    Alex Fidanov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Craig
    Craig avatar
    1 posts
    Member since:
    Mar 2011

    Posted 23 Mar 2011 Link to this post

    That seems like a reasonable solution, but it is a bit annoying if the user enters a '-' when the field has a 0 in it. It changes the text to "-$0.00", and any further number entries will be disallowed until they manually delete the '-' character. Is there a good way to prevent the dash character from showing up at all?
  5. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 24 Mar 2011 Link to this post

    Hello,

    I am not sure you could stop the negative char from appearing from the ValueChanging event. You could handle the KeyDown event when the e.Key is the subtract key. For example:

    this.AddHandler(RadMaskedTextBox.KeyDownEvent, new KeyEventHandler(OnKeyDown), true);
    void OnKeyDown(object sender, KeyEventArgs e)
    {
    e.Handled = e.Key == Key.Subtract;
    }

    Have you tried the new RadMaskedCurrency(Numeric)Input controls that we released in Q1 2011. We did some enhancements and one of them is value extensions. For example, you could use the following setup to allow only positive value in the control :

    <telerik:RadMaskedCurrencyInput xmlns:ext="clr-namespace:Telerik.Windows.Controls.MaskedInput;assembly=Telerik.Windows.Controls.Input" ext:MaskedInputExtensions.Minimum="0"/>

    You could use the same setup with the numeric input and format the text as currency :

    <telerik:RadMaskedNumericInput xmlns:ext="clr-namespace:Telerik.Windows.Controls.MaskedInput;assembly=Telerik.Windows.Controls.Input" ext:MaskedInputExtensions.Minimum="0"
    FormatString="c"/>
    however, the currency symbol will not be visible when the control is focused.

    Kind regards,
    Alex Fidanov
    the Telerik team

Back to Top