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

RadMaskedNumericInput throws exception with FormatString set to "D" or "d"

2 Answers 182 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 09 Sep 2013, 10:35 PM
I'm trying to use the RadMaskedNumericInput control in non-masking mode, and using the StringFormat to define an integer. According to the Standard Numeric Format Strings article from Microsoft, which Telerik references for using string formats, I should use either a "D" or "d" for the format string to get the desired result. However on running the code where I set it to that I get an exception that says "Format specifier was invalid" with the following stack trace:

   at System.Number.FormatDouble(Double value, String format, NumberFormatInfo info)
   at System.Double.ToString(String format, IFormatProvider provider)
   at Telerik.Windows.Controls.RadMaskedNumericInput.CoerceTextNoMask(Nullable`1 value)
   at Telerik.Windows.Controls.RadMaskedNumericInput.CoerceText(Nullable`1 value, Int32& selectionStart)
   at Telerik.Windows.Controls.RadMaskedNumericInput.CoerceTextOverride(Int32& selectionStart)
   at Telerik.Windows.Controls.RadMaskedInputBase.CoerceText()
   at Telerik.Windows.Controls.RadMaskedInputBase.ProcessValueChanged()
   at Telerik.Windows.Controls.RadMaskedInputBase.OnFormatStringChanged(DependencyObject d, DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)

Is there any way to limit the box to integers in no-mask mode?  Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Pavel R. Pavlov
Telerik team
answered on 12 Sep 2013, 08:34 AM
Hi Robert,

You need to keep in mind that the Value of the RadMaskedNumericInput control is of type nullable decimal (decimal?). On the other hand the format specifier "D" or "d" is used only over integer values. This is why you get the exception.

You can try to bind the native TextBox control to a double value and apply the "D" format specifier. If you do so you will replicate the same exception.

Also, you need to have in mind that the FormatString is applied only when the RadMaskedNumericInput is not focused. Hence, when you focus the control the Mask will be applied. Please have in mind that when you have defined no-mask you will not be able to enter a decimal point. This functionality is not yet implemented.

Regards,
Pavel R. Pavlov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Robert
Top achievements
Rank 1
answered on 12 Sep 2013, 08:12 PM
Ah, that explains it.

After looking further, it appears the RadNumericUpDown control might better suit my needs, especially as it still supports nullable value types.

Thanks!
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Robert
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Robert
Top achievements
Rank 1
Share this question
or