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

Positive Currency Values In WPF Telerik RadMaskTextBox Of Currency Mask

3 Answers 111 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Ruhban
Top achievements
Rank 1
Ruhban asked on 26 Feb 2011, 11:12 PM

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.

3 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 01 Mar 2011, 10:39 AM
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!
0
Craig
Top achievements
Rank 1
answered on 23 Mar 2011, 11:33 PM
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?
0
Alex Fidanov
Telerik team
answered on 24 Mar 2011, 09:07 AM
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

Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Ruhban
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Craig
Top achievements
Rank 1
Share this question
or