开发者

WPF: How do I set the focus on a datagrid to a specific row?

I would like to set the focus on the first row of a data grid.

Thi开发者_C百科s is what I have so far:

Keyboard.Focus(ResultsGrid)
If result.Count > 0 Then
    ResultsGrid.SelectedIndex = 0
End If

This will set the focus to the datagrid, but not the row itself.


After selecting the row you will have to set the focus on the row in the following way:

ResultsGrid.SelectedIndex = index;
DataGridRow row = (DataGridRow)ResultsGrid.ItemContainerGenerator.ContainerFromIndex(index);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));


Try this:

yourDataGrid.SelectedItem = yourDataGrid.Items[i];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜