WPF DataGrid-如何在按Tab键后将键盘焦点移动到新添加的行 [英] WPF DataGrid - How to move keyboard focus to newly added row after tab press

查看:362
本文介绍了WPF DataGrid-如何在按Tab键后将键盘焦点移动到新添加的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们在最后一行的最后一列上按Tab键,则WPF DataGrid将添加新行。但是在添加新行之后,焦点将移至网格的第一行。我们如何确保焦点移到新行的第一列?

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?

推荐答案

您可以尝试类似

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();
}

这篇关于WPF DataGrid-如何在按Tab键后将键盘焦点移动到新添加的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆