не уверен, как выглядит ваш шаблон, но я думаю, вы можете рассмотреть возможность выбора всей строки вашей сетки, установив ее свойство SelectionUnit = "FullRow" и выполнив код ниже; выделите всю строку с индексом 3
int index = 3;
dataGrid.SelectedItem = dataGrid.Items[index];
dataGrid.ScrollIntoView(dataGrid.Items[index]);
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.Items[index]);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
если вы все еще хотите выбрать ячейку, проверьте, будет ли работать код ниже, она выберет ячейку с индексом 2 для строки с индексом 3
int index = 3;
dataGrid.ScrollIntoView(dataGrid.Items[index]);
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.Items[index]);
if (row != null)
{
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(row);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(2);
if (cell != null)
{
cell.IsSelected = true;
cell.Focus();
}
}
Реализация процедуры GetVisualChild:
static T GetVisualChild<T>(Visual parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
надеюсь, это поможет, с уважением