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

3 posts, 1 answers
  1. Robert
    Robert avatar
    15 posts
    Member since:
    Mar 2013

    Posted 09 Sep 2013 Link to this post

    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. Answer
    Pavel R. Pavlov
    Pavel R. Pavlov avatar
    1165 posts

    Posted 12 Sep 2013 Link to this post

    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.

    Pavel R. Pavlov
    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 >>
  3. DevCraft R3 2016 release webinar banner
  4. Robert
    Robert avatar
    15 posts
    Member since:
    Mar 2013

    Posted 12 Sep 2013 Link to this post

    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.

Back to Top