I am using WPF toolkit provided DataGrid control to display product list along with its OpenStock, Description etc. In this DataGrid i have set OpenStock column to editable
I have datagrid with TextBox in DataTemplate of DataGridTemplateColumn. Also i am using Enter instead of Tab to focus TextBox
private void DataGrid_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
e.Handled = true;
var TabKey = new KeyEventArgs(e.KeyboardDevice, e.InputSource, e.Timestamp, Key.Tab);
TabKey.RoutedEvent = Keyboard.KeyDownEvent;
InputManager.Current.ProcessInput(TabKey);
}
}
I solve focus problem with combination of this code:
dataGrid.Focus();
//In case of more columns
//dataGrid.CurrentCell = new DataGridCellInfo(dataGrid.Items[0], dataGrid.Columns[1]);
dataGrid.BeginEdit();
(Keyboard.FocusedElement as UIElement).MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));