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

Numeric input with decimals in GridViewMaskedInputColumn

1 Answer 367 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 14 Jul 2016, 05:45 PM

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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Stefan Nenchev
Telerik team
answered on 19 Jul 2016, 07:59 AM
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.
Tags
GridView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Share this question
or