Numeric input with decimals in GridViewMaskedInputColumn

2 posts, 1 answers
  1. Daniel
    Daniel avatar
    4 posts
    Member since:
    Aug 2015

    Posted 14 Jul Link to this post

    I'm using RadGridView with GridViewMaskedInputColumn like that:

    <telerik:GridViewMaskedInputColumn DataMemberBinding="{Binding RealCurrent, Mode=TwoWay}" DataFormatString="n2" Width="85" Style="{StaticResource BlueGridViewColumnStyle}" Header="{x:Static commonResources:ControlResources.RealCurrent }"/>

    This is great, because in the column I see numbers rounded to 2 digits after decimal point.

    But when I want to edit it and I delete whole number I cannot type decimal point...

     

    I can fix it by adding Mask="#1.2", but than I can type only one digit BEFORE decimal point and I see underscore as a placeholder. I don't want to have any limitations for that (user should be able to place 0.55, 45.8, 131645651654.1 or whatever) and any underscores. How to achieve this?

  2. Answer
    Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 19 Jul Link to this post

    Hi Daniel,

    Thank you for providing the implementation at your end. 

    Basically, to achieve the desired behavior, a MaskedInput column is not required. You can use a GridViewDataColumn and apply the DataFormatString to be the one you are currently using. Eventually, you need to modify the CellEditTemplate of the column and apply the same format there. Here is an example column that shows the requirement:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding MarketValue}"
                                              DataFormatString="n2">
                      <telerik:GridViewDataColumn.CellEditTemplate>
                          <DataTemplate>
                              <TextBox Text="{Binding MarketValue, StringFormat=n2}"></TextBox>
                          </DataTemplate>
                      </telerik:GridViewDataColumn.CellEditTemplate>
    </telerik:GridViewDataColumn>

    I have also added a sample project that shows the aforementioned approach. Please review it and update me whether it was useful. I will be looking forward to your reply.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top