How do I allow decimals to be copied into Infragistics Grid using clipboard operations?

58 Views Asked by At

I have a WPF project with an XamDatagrid that utilizes clipboard operations. I am currently allowing a user to paste a decimal into the grid, but when the user pastes in a decimal with a comma - example: 1,234.987 - I get an error saying "Unable to convert the value to the destination type, value 1,234.987 is not a valid number". However, when pasting in 1234.987, I have zero issues. How do I allow for the comma???

 <igDp:XamDataGrid.FieldLayouts>
                        <igDp:FieldLayout >
                            <igDp:FieldLayout.Fields>
                                <igDp:Field Name="Field1" Label="Field1" Width="100" AllowEdit="False"></igDp:Field>
                                <igDp:Field Name="DecimalField" Label="DecimalField" Width="100*">
                                    <igDp:Field.Settings>
                                        <igDp:FieldSettings
                                            EditAsType="{x:Type sys:Decimal}">
                                            <igDp:FieldSettings.EditorStyle>
                                                <Style TargetType="{x:Type igEditors:XamMaskedEditor}">
                                                    <Setter Property="Mask" Value="99999.999" />
                                                </Style>
                                            </igDp:FieldSettings.EditorStyle>
                                        </igDp:FieldSettings>
                                    </igDp:Field.Settings>
                                </igDp:Field>
                            </igDp:FieldLayout.Fields>
                        </igDp:FieldLayout>
                    </igDp:XamDataGrid.FieldLayouts>
1

There are 1 best solutions below

0
AndrewS On

Your mask ("99999.999") is such that you are just specifying optional numeric digits but that doesn't mean as a whole it's a number so when you paste the editor just applies the characters in the text coming from the clipboard to the mask characters and since the ',' doesn't fit/match it's an error. It would be better if you used the n's to specify that it's a numeric section (of a specific size). e.g. "nnnnn.nnn". When you do that the paste works because it will ignore/skip digit grouping symbols like the ','. See the masks help for more on those characters.

Unrelated to this I would highly suggest you change your field to be the specific editor type so you can set properties on it without needing to use a style. In this way you also won't step on any styling that might be provided for that element if you were to set the Theme.

e.g.

<igWpf:MaskedTextField 
    Name="DecimalField" 
    Label="DecimalField"
    Width="100*"
    EditAsType="{x:Type sys:Decimal}"
    Mask="nnnnn.nnn">
</igWpf:MaskedTextField>

Also you might get quicker support if you post on the Infragistics forums directly.