GridViewMaskedTextBoxColumn throwing validation errors for numeric input with MaskType="Numeric"

2 posts, 1 answers
  1. Hasanain
    Hasanain avatar
    8 posts
    Member since:
    Jun 2012

    Posted 27 Jul 2012 Link to this post

    Hello,

    I have the following column defined in my xaml code

    <
    telerik:GridViewMaskedTextBoxColumn Mask="P1" MaskType="Numeric" 
    DataMemberBinding="{Binding CurrentAllocationWeight}" 
    DisplayIndex="1" IsReadOnly="True" DataFormatString="{}{0:P1}"  
    Header="% Of Total" ColumnGroupName="CurrentAllocation"/> 

    The bound property is a null-able decimal value. I have no other validation in the code-behind. When I try to enter a value in the cell, I get a validation error: "DecimalConverter cannot convert from System.Double".

    How should I fix this, so that the user can enter say, 5.5, and it would display that value as "5.5%" in the cell?

    Hasanain
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 27 Jul 2012 Link to this post

    Hello,

     If you want to bind the GridViewMaskedTextBoxColumn to Decimal or Int , you should use Converter for the Binding. In the ConvertBack method you should manually convert back from Double.

    As to the DataFormatString you could define it like so: 

    DataFormatString="{}{0:#%}"

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top