Hey, I'll ask again. How can i set the AddNewRecord special row's first cell to be automatically selected and in edit mode after I add a record (by pressing enter key)? I have AllowAddNew="true" and AddNewRecordLocation="OnBottomFixed". Surely someone knows how to do this. I just want the first cell in that special row (with the +) to be ready for user to type in for adding records quickly.
private void dp_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
XamDataPresenter dp = sender as XamDataPresenter;
if (dp != null)
}
Hello,
I have been looking into this and can suggest you use the RecordAdded and RecordUpdated events to get this functionality like so:
public Record flag;
private void xamDataGrid1_RecordAdded(object sender, RecordAddedEventArgs e)
flag = e.Record;
private void xamDataGrid1_RecordUpdated(object sender, RecordUpdatedEventArgs e)
if (e.Record == flag)
e.Record.RecordManager.CurrentAddRecord.Cells[0].IsActive = true;
xamDataGrid1.ExecuteCommand(DataPresenterCommands.StartEditMode);
flag = null;
Here is a also a code snippet you can use to replace the bolded text in your description:
if ((xamDataGrid1.ActiveRecord!=null) && (xamDataGrid1.ActiveRecord as DataRecord).IsAddRecord)
xamDataGrid1.ActiveRecord.RecordManager.CommitAddRecord();
Dispatcher.BeginInvoke(new Action(() =>
xamDataGrid1.ActiveRecord.RecordManager.CurrentAddRecord.Cells[0].IsActive = true;
}), System.Windows.Threading.DispatcherPriority.Background, null);
Please let me know if you require any further assistance on the matter.
Sincerely,
Petar Monov
Developer Support Engineer
Infragistics Bulgaria
www.infragistics.com/support
Thanks a lot Peter, the second solutions works fine. However, i would like to use the first as it seems better to me. But it doesn't quite work. Edit Mode is not started in first solution. It works after I combine the two so that :
private void XamDataPresenter1_RecordUpdated(object sender, Infragistics.Windows.DataPresenter.Events.RecordUpdatedEventArgs e) { if (e.Record == flag) { XamDataPresenter dp = sender as XamDataPresenter; Dispatcher.BeginInvoke(new Action(() => { dp.ActiveRecord.RecordManager.CurrentAddRecord.Cells[0].IsActive = true; dp.ExecuteCommand(DataPresenterCommands.StartEditMode); }), System.Windows.Threading.DispatcherPriority.Background, null); } }
Since I'm new to all of this, I would like to understand why the first solution as you proposed doesn't work for me and what you suggest it needs to fix (Why do I need the Dispatcher stuff?). I included a sample application for you to try.