How to move selection to record when add the new row in SfDataGrid contains empty record in WPF DataGrid (SfDataGrid)?
The current cell will remain in the AddNewRow after adding a record when the grid has no records in WPF DataGrid (SfDataGrid). But, you can move the current cell to the newly added record by moving the current cell in SfDataGrid.RowValidated event using the ScrollInView() method. You can also change the AddNewRow state to the normal using VisualStateManager.GoToState() method.
//Event subscription this.datagrid.RowValidated += sfdatagrid_RowValidated; //Event customization. private void sfdatagrid_RowValidated(object sender, RowValidatedEventArgs e) { var addNewRow = this.datagrid.RowGenerator.Items.FirstOrDefault(item => item.RowType == RowType.AddNewRow); if (datagrid.IsAddNewIndex(e.RowIndex)) { datagrid.Dispatcher.BeginInvoke(new Action(() => { datagrid.SelectedItem = e.RowData; //To move the current cell. datagrid.ScrollInView(datagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex); usetransition = true; //To change the AddNewRow state. VisualStateManager.GoToState(addNewRow.Element, "Normal", usetransition); usetransition = false; })); } }
Hope you enjoyed learning about how to move selection to record when add the new row in SfDataGrid contains empty record in WPF DataGrid (SfDataGrid).
You can refer to our WPF DataGrid feature tour page to learn about its other groundbreaking feature representations. You can explore our WPF DataGrid documentation to understand how to present and manipulate data.
For current customers, you can check out our Angular components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Angular Diagram and other Angular components.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!