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

Column's decimal precision and scale

8 Answers 472 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jan Paolo
Top achievements
Rank 1
Jan Paolo asked on 17 Dec 2018, 06:16 PM

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

Sort by
0
Stefan
Telerik team
answered on 20 Dec 2018, 12:18 PM
Hello Jan,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jan Paolo
Top achievements
Rank 1
answered on 20 Dec 2018, 08:33 PM

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

0
Jan Paolo
Top achievements
Rank 1
answered on 20 Dec 2018, 08:49 PM

Also, how do we remove the underscores? Please see attached image.

Thanks!

0
Stefan
Telerik team
answered on 24 Dec 2018, 03:50 PM
Hi Jan,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jan Paolo
Top achievements
Rank 1
answered on 26 Dec 2018, 04:45 PM

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>
0
Martin Ivanov
Telerik team
answered on 31 Dec 2018, 09:04 AM
Hello Jan,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Jan Paolo
Top achievements
Rank 1
answered on 07 Jan 2019, 08:50 PM

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)?

0
Martin Ivanov
Telerik team
answered on 08 Jan 2019, 02:44 PM
Hello Jan,

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
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Jan Paolo
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Jan Paolo
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or