Search code examples
c#wpfteleriktelerik-gridradgridview

"Enter" key not leaving cell in RadGridView


All around my project I'm facing similar problem, which is "Enter" key, creating new line in cell, instead of move to next line.

My current telerik version is 2018.1.122.45, and default, expected behavior is to leave cell, after pressing "Enter" key (according to telerik documentation, and helpdesk).

However, in my case it always makes new line within cell being edited. I'm using Visual Studio 2013 theme, my implementation of RadGridView is correct, I've pasted my RadGridView, to project, I got from telerik support, and there, Enter was working as expected. Also, they've pasted my RadGridView implementation to their project and it also worked correctly.

Have anyone faced similar problem? I'm looking for solution, since I can't track source of this issue (even with teleriks help).


Solution

  • I've found a solution to this problem, and other Styles problems. Implementing style in the way demonstrated in telerik documentation (f.e. https://docs.telerik.com/devtools/wpf/controls/radgridview/styles-and-templates/styling-a-row) has some issues not mentioned in documentation.

    <Style TargetType="telerik:GridViewRow">
       <Setter Property="Background" Value="Red"/>
       <Setter Property="Foreground" Value="White"/>
    </Style>
    

    This is one of the simpliest examples of implementing style. In my case it was:

    <Style TargetType="telerik:GridViewCell"
                   x:Key="IloscNormalStyle"
                   BasedOn="{StaticResource GridViewCellStyle}">
                <Setter Property="Background"
                        Value="#c3d8c7" />
                <Setter Property="Foreground"
                        Value="Black" />
    
    </Style>
    

    And it works just fine. The biggest issue is that it completly ignores implemented Theme for project and all it's behaviours, which are, for example, selection behavior, enter key press, borders, etc. In order to tell style to not ignore implemented theme, I needed to insert this code to my styles:

    <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:GridViewRow}}"
                                 Value="True">
                        <Setter Property="Background"
                                Value="{Binding Background}" />
                    </DataTrigger>
    </Style.Triggers>
    

    Which finally made my style works with desired behavior. Full style code:

    <Style TargetType="telerik:GridViewCell"
                   x:Key="IloscNormalStyle"
                   BasedOn="{StaticResource GridViewCellStyle}">
                <Setter Property="Background"
                        Value="#c3d8c7" />
                <Setter Property="Foreground"
                        Value="Black" />
                <Style.Triggers>
                    <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=telerik:GridViewRow}}"
                                 Value="True">
                        <Setter Property="Background"
                                Value="{Binding Background}" />
                    </DataTrigger>
                </Style.Triggers>
    </Style>
    

    I think it is a major issue for telerik (or maybe even WPF), but this couple lines of code resolves most of problems with custom cell/row styling.