1

I've researched all this 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 (or Return) 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 MyNumberTextBox_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.

blcamp
  • 119
  • 15
  • Similar question is answered here: https://stackoverflow.com/questions/10404681/move-focus-to-next-cell-on-enter-key-press-in-wpf-datagrid – D_Learning Feb 23 '18 at 20:31
  • Possible duplicate of [Move Focus to Next Cell on Enter Key Press in WPF DataGrid?](https://stackoverflow.com/questions/10404681/move-focus-to-next-cell-on-enter-key-press-in-wpf-datagrid) – D_Learning Feb 23 '18 at 20:38
  • Similar, yes, but not a duplicate. That example did not work for me. Focus did not advance. – blcamp Feb 23 '18 at 21:34

0 Answers0