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.