I have a XamDataGrid (version 2011.2) in a WPF application, when a user has tabbed off of the "Add New" row I need the focus to return to the first cell of the Add New row so they can enter another record, the default behaviour keeps the focus on the record that has just been added.

I have tried to use DataPresenterCommands to move the focus or to find a way to set myGrid.Records.DataPresenter.ActiveCell but haven't had any success.

I need the same functionality as mentioned in this question but for Infragistics' XamDataGrid.

Does anyone have any ideas?

有帮助吗?

解决方案

Thanks to Yanko Nikolov on the Infragistics support forum for finding a solution (which I had somehow missed in my search for a answer).

The solution is to add this code to the preview key down event of the data grid.

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);
     }         
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top