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

Enter Key = Tab Key... Not Working

2 Answers 668 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 23 Feb 2018, 07:46 PM

I've researched all morning how to modify the behavior of a RadGridView (in WPF) for moving focus from one control to the next, just like the Tab key does...  and like many other examples I've seen, I want to do the same thing: just make the Enter Key mimic the Tab key. But my code is not working.

If I have the following code in XAML:

                <telerik:GridViewDataColumn Name="MyColumn" CellStyleSelector="{DynamicResource MyColorStyle}" Width="64">
                    <telerik:GridViewDataColumn.Header>
                        <TextBlock Text="My Column" TextAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" />
                    </telerik:GridViewDataColumn.Header>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding MyNumber}" TextAlignment="Right"></TextBlock>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewColumn.CellEditTemplate>
                        <DataTemplate>
                            <TextBox Name="MyNumberTextBox" Text="{Binding MyNumber, Mode=TwoWay}" IsTabStop="True" TabIndex="27" PreviewKeyDown="MyNumberTextBox_PreviewKeyDown" MaxLength="10" HorizontalAlignment="Stretch" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>

And I have this code in the code-behind:

private void TextBox_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if ((e.Key == Key.Enter) || (e.Key == Key.Return))
    {
        e.Handled = true;
        (sender as TextBox).MoveFocus(new TraversalRequest(System.Windows.Input.FocusNavigationDirection.Next));
    }
}

 

The focus does not advance to the next column immediately to the right on the RadGridView row; it instead advances back to the top of the screen (to a pulldown menu control). I have TabStops explicitly set for every textbox in my column(s).

Could use some help here to determine what I am not doing properly, or what I may be missing. Thanks in advance for your help.

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
Maurice
Top achievements
Rank 1
answered on 28 Feb 2018, 02:50 AM

Hi Barry,

Have you tried using a Custom Keyboard Command Provider?

https://docs.telerik.com/devtools/wpf/controls/radgridview/commands/keyboardcommandprovider

 

Regards,
Maurice

0
Barry
Top achievements
Rank 1
answered on 28 Feb 2018, 01:56 PM
No. Never heard of it. I guess I'll consider it if I run into this issue again...  but I've already had to find another way to solve this problem.
Tags
GridView
Asked by
Barry
Top achievements
Rank 1
Answers by
Maurice
Top achievements
Rank 1
Barry
Top achievements
Rank 1
Share this question
or