如何在添加行后将键盘焦点设置为“添加行”

时间:2012-08-07 14:26:15

标签: wpf infragistics xamdatagrid

我在WPF应用程序中有一个XamDataGrid(版本2011.2),当用户选中“添加新”行时,我需要将焦点返回到“添加新行”的第一个单元格,这样他们就可以了可以输入另一条记录,默认行为将焦点放在刚刚添加的记录上。

我尝试使用DataPresenterCommands移动焦点或找到设置myGrid.Records.DataPresenter.ActiveCell的方法,但没有取得任何成功。

我需要与this question中提到的功能相同的功能,但需要Infragistics的XamDataGrid。

有没有人有任何想法?

1 个答案:

答案 0 :(得分:2)

感谢Infragistics支持论坛上的Yanko Nikolov寻找解决方案(我在寻找答案时遗漏了一些错误)。

解决方案是将此代码添加到数据网格的预览键向下事件中。

private void xamDataGrid1_PreviewKeyDown(object sender, KeyEventArgs e)
{
     if (e.Key == Key.Enter)
     {
         Dispatcher.BeginInvoke(new Action(() =>
         {
             CellValuePresenter.FromCell(xamDataGrid1.RecordManager.CurrentAddRecord.Cells[0]).Editor.StartEditMode();
         }), DispatcherPriority.Background, null);
     }         
}
相关问题