This is my code
Version 1
public void scrollIntoGrid(DataGrid grid)
{
object item = grid.Items[0];
grid.SelectedItem = item;
grid.ScrollIntoView(item);
grid.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
grid.SelectedIndex = 0;
//DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);
//row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Left));
//row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
}
Version 2
public void scrollIntoGrid(DataGrid grid)
{
object item = grid.Items[0];
grid.SelectedItem = item;
grid.ScrollIntoView(item);
//grid.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
//grid.SelectedIndex = 0;
DataGridRow row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
//row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Up));
}
and all iterations go to second row in grid and not the first.
coming back to this after some time, the solution I found working is on KeyUp event in text box.
if (e.Key == Key.Down)
{
object item = dgProductSaleInvSm.Items[0];
dgProductSaleInvSm.SelectedItem = item;
dgProductSaleInvSm.ScrollIntoView(item);
DataGridRow row = (DataGridRow)dgProductSaleInvSm.ItemContainerGenerator.ContainerFromIndex(0);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
}