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

Edit Numeric Values

4 Answers 340 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Thilo
Top achievements
Rank 1
Iron
Thilo asked on 30 Jan 2014, 03:47 PM
Hello !
I want to Edit Numeric Values with 2 digits in an GridView.

My First Solution:
Using an GridViewDataColumn and set the CellEditTemplate to a
RadMaskedNumericInput like this (SelectionOnFocus="SelectAll" (Important!))
<telerik:GridViewDataColumn Header="Listenpreis" Width="80" TextAlignment="Right" HeaderTextAlignment="Right"
                            DataMemberBinding="{Binding Path=Listenpreis}" DataFormatString="F2">
  <telerik:GridViewDataColumn.CellEditTemplate>
     <DataTemplate>
        <telerik:RadMaskedNumericInput Margin="0" SelectionOnFocus="SelectAll" HorizontalAlignment="Stretch"
               Value="{Binding Path=Listenpreis, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged}"
               SpinMode="None"
               FormatString="n2"/>
     </DataTemplate>
  </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
This works well for Editing, but the Enter Key doesn't work as expected to go to the next Row in the same Column.
I can Only change the Column with the Tab Key.

My Second Solution:
Using an GridViewMaskedInputColumn like this:
<telerik:GridViewMaskedInputColumn Header="Listenpreis3" Width="80" TextAlignment="Right" HeaderTextAlignment="Right"
                                   MaskType="Numeric"
                                   DataMemberBinding="{Binding Path=Listenpreis}" DataFormatString="{} {0:N2}"  />

But here i'am missing the 2 Digits Mask on Editing and "SelectAll" on Enter the Cell.

How can i get this working as expected ?

4 Answers, 1 is accepted

Sort by
0
Thilo
Top achievements
Rank 1
Iron
answered on 30 Jan 2014, 08:47 PM
OK, my Working Solution is to define the EditorStyle like this:
<telerik:GridViewMaskedInputColumn x:Name="listenpreisColumn" Header="Listenpreis" Width="90" TextAlignment="Right" HeaderTextAlignment="Right"
                                   MaskType="Numeric"
                                   DataMemberBinding="{Binding Path=Listenpreis}" DataFormatString="{} {0:N2}" >
    <telerik:GridViewMaskedInputColumn.EditorStyle>
        <Style TargetType="telerik:RadMaskedNumericInput">
            <Setter Property="SelectionOnFocus" Value="SelectAll" />
            <Setter Property="FormatString" Value="N2" />
            <Setter Property="SpinMode" Value="None" />
        </Style>
    </telerik:GridViewMaskedInputColumn.EditorStyle>
</telerik:GridViewMaskedInputColumn>
0
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 15 Feb 2021, 11:34 AM

Hello,

I have a similiar problem. I cannot confirm the input with the return/enter key. The use of EditorStyle-Property is not an option, because I am using the EditCellTemplateSelector for switching between hex and dec input.

Here is my GridViewColumn:

<telerik:GridViewDataColumn Header="{lex:Loc IDS_LIST_VALUES_COLUMN_VALUE}" Width="100"
                            SortMemberPath="Value">
 
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding ValueString}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
 
    <telerik:GridViewDataColumn.CellEditTemplateSelector>
        <utils:HexDecEditCellTemplateSelector>
            <utils:HexDecEditCellTemplateSelector.cellTemplateHexEdit>
                <DataTemplate>
                    <telerik:RadMaskedTextInput Style="{StaticResource RadMaskedNumericInputHexStyle}"
                                                Mask=">X8"
                                                Value="{Binding ValueEditString, ValidatesOnDataErrors=True}"/>
                </DataTemplate>
            </utils:HexDecEditCellTemplateSelector.cellTemplateHexEdit>
            <utils:HexDecEditCellTemplateSelector.cellTemplateDecEdit>
                <DataTemplate>
                    <!-- TODO: Input confirmation with Enter does not work here -->
                    <telerik:RadMaskedNumericInput Style="{StaticResource RadMaskedNumericInputDezStyle}"
                                                   Value="{Binding ValueEditString, ValidatesOnDataErrors=True}"/>
                </DataTemplate>
            </utils:HexDecEditCellTemplateSelector.cellTemplateDecEdit>
        </utils:HexDecEditCellTemplateSelector>
    </telerik:GridViewDataColumn.CellEditTemplateSelector>
     
</telerik:GridViewDataColumn>

 

Can you help me with that plz?

 

regards,

Tobias

0
Dilyan Traykov
Telerik team
answered on 18 Feb 2021, 09:23 AM

Hello Peter,

Thank you for the provided code snippet.

One approach I can suggest with your particular setup would be to set the AcceptsReturn property of the two masked input controls to False.

                    <telerik:GridViewDataColumn.CellEditTemplateSelector>
                        <telerik:GridViewDataColumn.CellEditTemplateSelector>
                            <utils:HexDecEditCellTemplateSelector>
                                <utils:HexDecEditCellTemplateSelector.cellTemplateHexEdit>
                                    <DataTemplate>
                                        <telerik:RadMaskedTextInput Style="{StaticResource RadMaskedNumericInputHexStyle}"
                                                Mask=">X8" 
                                                AcceptsReturn="False"
                                                Value="{Binding ValueEditString, ValidatesOnDataErrors=True}"/>
                                    </DataTemplate>
                                </utils:HexDecEditCellTemplateSelector.cellTemplateHexEdit>
                                <utils:HexDecEditCellTemplateSelector.cellTemplateDecEdit>
                                    <DataTemplate>
                                        <!-- TODO: Input confirmation with Enter does not work here -->
                                        <telerik:RadMaskedNumericInput Style="{StaticResource RadMaskedNumericInputDezStyle}"
                                                                       AcceptsReturn="False"
                                                                       Value="{Binding ValueEditString, ValidatesOnDataErrors=True}"/>
                                    </DataTemplate>
                                </utils:HexDecEditCellTemplateSelector.cellTemplateDecEdit>
                            </utils:HexDecEditCellTemplateSelector>
                        </telerik:GridViewDataColumn.CellEditTemplateSelector>
                    </telerik:GridViewDataColumn.CellEditTemplateSelector>

Could you please give this a try and let me know if this approach works for you? I will be awaiting your reply.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 22 Feb 2021, 10:01 AM
That does the trick! Tanks!
Tags
GridView
Asked by
Thilo
Top achievements
Rank 1
Iron
Answers by
Thilo
Top achievements
Rank 1
Iron
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Dilyan Traykov
Telerik team
Share this question
or