How do I get the CurrentAddRecord of the active group?
Hello,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well. I have been looking into your code and I can say that it is a good approach and if I think of something better, I will let you know.
Thanks again.
Thanks for the repl.
That gets me part of the way there. I need to get the CurrentAddRecord according to which part of the grid has focus, even if a cell is not selected. This is what I ended up doing. If you see a better way am all ears.
XamDataGrid DataGrid = UIHelper.FindVisualChild<XamDataGrid>(AssociatedObject); DataRecord CurrentAddRow = null; if (DataGrid != null) { if (DataGrid.ActiveCell != null && DataGrid.ActiveCell.Record.RecordManager.CurrentAddRecord != null) CurrentAddRow = DataGrid.ActiveCell.Record.RecordManager.CurrentAddRecord; else if (DataGrid.RecordManager != null && DataGrid.RecordManager.CurrentAddRecord != null) CurrentAddRow = DataGrid.RecordManager.CurrentAddRecord; else if (DataGrid.ActiveRecord != null && DataGrid.ActiveRecord is GroupByRecord) CurrentAddRow = TryGetGroupChildCurrentAddRow(DataGrid.ActiveRecord as GroupByRecord); else if (DataGrid.ActiveRecord != null && DataGrid.ActiveRecord is DataRecord) CurrentAddRow = (DataGrid.ActiveRecord as DataRecord).RecordManager.CurrentAddRecord; } if (CurrentAddRow != null) { CellValuePresenter FieldNamePresenter = CellValuePresenter.FromRecordAndField(CurrentAddRow, CurrentAddRow.FieldLayout.Fields[FocusFieldName]); if (FieldNamePresenter != null) { Dispatcher.BeginInvoke(new Action(() => { FieldNamePresenter.Editor.StartEditMode(); }), DispatcherPriority.Normal, null); } }
private DataRecord TryGetGroupChildCurrentAddRow(GroupByRecord groupByRecord) { try { foreach (DataRecord GroupChild in groupByRecord.ChildRecords) { if (GroupChild != null) { if (GroupChild.RecordManager.CurrentAddRecord != null) return GroupChild.RecordManager.CurrentAddRecord; else { foreach (ExpandableFieldRecord FieldRecord in GroupChild.ChildRecords) { if (FieldRecord != null) { if (FieldRecord.ChildRecordManager.CurrentAddRecord != null) return FieldRecord.ChildRecordManager.CurrentAddRecord; } } } } } return null; } catch { return null; } }
Thank you for your post. I have been looking into it and I suggest you use the following code to get the current add new record:
xamDataGrid1.ActiveCell.Record.RecordManager
Please let me know if this hasp you or you need further assistance on this matter.
Looking forward for your reply.