sfdatagrid.RowValidated+=sfdatagrid_RowValidated;
void sfdatagrid_RowValidated(object sender, RowValidatedEventArgs args) { if(sfdatagrid.IsAddNewIndex(args.RowIndex)) { sfdatagrid.Dispatcher.BeginInvoke(new Action(() => { sfdatagrid.SelectedItem = args.RowData; sfdatagrid.ScrollInView(sfdatagrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex); })); } |
sfDataGrid.CurrentCellActivating += sfDataGrid_CurrentCellActivating;
sfDataGrid.View.Records.CollectionChanged += Records_CollectionChanged;
void Records_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
{
// To scroll the grid to the newly added row position.
var scrollValue = this.sfDataGrid.TableControl.ScrollRows.Distances.GetCumulatedDistanceAt(e.NewStartingIndex);
this.sfDataGrid.TableControl.ScrollRows.ScrollInView(e.NewStartingIndex);
this.sfDataGrid.TableControl.VerticalScroll.Value = (int)scrollValue;
sfDataGrid.TableControl.BeginInvoke(new Action(() =>
{
this.sfDataGrid.SelectedItem = e.NewItems[0];
}));
}
}
void sfDataGrid_CurrentCellActivating(object sender, Syncfusion.WinForms.DataGrid.Events.CurrentCellActivatingEventArgs e)
{
if (sfDataGrid.IsAddNewRowIndex(sfDataGrid.CurrentCell.RowIndex) && sfDataGrid.View.IsAddingNew && e.DataRow.RowIndex == sfDataGrid.GetAddNewRowIndex() + 1)
{
e.Cancel = true;
}
} |