WPF DataGrid - How to move keyboard focus to newly added row after tab press

馋奶兔 提交于 2019-12-06 00:18:35

问题


WPF DataGrid add a new row if we press tab on last column of last row. But after adding the new row, the focus is moved to top row of the grid. How can we make sure that the focus is moved to the first column of new row?


回答1:


You could try something like

this.SelectRowCell(this.Items.Count - 1, 0);

But I'm not sure if that will set the focus too. If not then try the following:

DataGridCell cell = this.GetCell(this.Items.Count - 1, 0);

if (cell != null)
{
    cell.Focus();
}


来源:https://stackoverflow.com/questions/2645027/wpf-datagrid-how-to-move-keyboard-focus-to-newly-added-row-after-tab-press

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!