Hello,
Is there a way to set precision and scale for a column bound to a decimal (or double) property?
I see WinForms has a GridViewDecimalColumn.
Also, is it possible to do it using attached property similar to MaxLength as described here.
Thank you,
Jan
8 Answers, 1 is accepted
Thank you for the referred article.
In order to achieve a similar result with the UI for WPF RadGridView you can benefit from the GridViewMaskedInputColumn. Can you please check it out? Its usage is also demonstrated in the Column Types WPF Demo so you may find it useful.
I hope this helps, Jan. Let me know in case I can be of further assistance.
Regards,
Stefan
Progress Telerik

Hello Stefan,
Thanks for the suggestion. How do I have the GridViewMaskedInputColumn keep the editor to be left-aligned? Please see attached image that describes issue.
Thanks,
Jan

Also, how do we remove the underscores? Please see attached image.
Thanks!
Since the GridViewMaskedInputColumn uses a RadMaskedNumericInput as its editor for a Numeric MaskType, you can use the following Style to achieve your goal.
<
Style
TargetType
=
"telerik:RadMaskedNumericInput"
>
<
Setter
Property
=
"Placeholder"
Value
=
" "
/>
<
Setter
Property
=
"HorizontalContentAlignment"
Value
=
"Left"
/>
</
Style
>
Can you please give the approach a try?
Note, that in case you need to apply the Style to a given column only, you can set an x:Key to the Style and apply it through the EditorStyle property of the column.
I hope this helps.
Regards,
Stefan
Progress Telerik

Hello Stefan,
Thanks for the response.
The HorizontalContentAlignment works but the Placeholder just replaces the underscore with spaces. Please see attached image.
We've also tried setting AutoFillNumberGroupSeparators to false to hide the commas but we still have spaces on the left of the value.
Thanks,
Jan
Below is a sample of our code.
<
t:GridViewMaskedInputColumn
DataMemberBinding
=
"{Binding Price}"
Header
=
"Price"
Mask
=
"#19.4"
MaskType
=
"Numeric"
>
<
t:GridViewMaskedInputColumn.EditorStyle
>
<
Style
TargetType
=
"{x:Type t:RadMaskedNumericInput}"
>
<
Setter
Property
=
"Placeholder"
Value
=
" "
/>
<
Setter
Property
=
"HorizontalContentAlignment"
Value
=
"Left"
/>
<
Setter
Property
=
"AutoFillNumberGroupSeparators"
Value
=
"False"
/>
</
Style
>
</
t:GridViewMaskedInputColumn.EditorStyle
>
</
t:GridViewMaskedInputColumn
>
To avoid showing the placeholders you can just set the Mask property of the control to an empty string. However, this way you will loose the value restriction, like the required number of digits after and before the decimal point. If you want to have some kind of dynamic format where you want to restrict the value, but don't want the placeholders, you can try the approach shown in the DynamicFormatString SDK example. Note that, if this works for you, you will need to use a bit different approach to use the input control. Basically, you will need to use a GridViewDataBoundColumn with custom CellTemplate and CellEditTemplate that contain the custom RadMaskedNumericInput control. Or you can create a custom gridview column and override the methods responsible for creating the editor element.
If you decide to use this approach and have trouble adopting the custom control within the gridview, please don't hesitate to let me know.
Alternatively, you can use the RadNumericUpDown control with its up/down buttons hidden. I've attached a small example showing this approach. Can you please give it a try and let me know how it goes?
Regards,
Martin Ivanov
Progress Telerik

Hello Martin, thank you for the suggestions. Is there a way to do this on a single line? similar to how we can set Mask="#19.4" or creating an attached property (see https://www.telerik.com/forums/best-way-to-set-maxlength-on-gridviewdatacolumn#OpuGlbdurkKX2uxPqIZMhg)?
I am not sure which one you are referring to. Can you tell me which approach you want to apply using a single line of code?
Regards,
Martin Ivanov
Progress Telerik