private void commit_Click(object sender, EventArgs e)
{
var rowIndex = this.sfDataGrid.CurrentCell != null ? this.sfDataGrid.CurrentCell.RowIndex : 0;
if (this.sfDataGrid.IsAddNewRowIndex(rowIndex))
{
if (this.sfDataGrid.CurrentCell.IsEditing)
this.sfDataGrid.CurrentCell.EndEdit(true);
var rowColumnIndex = new RowColumnIndex(this.sfDataGrid.CurrentCell.RowIndex, this.sfDataGrid.CurrentCell.ColumnIndex);
var gridModel = ReflectionHelper.GetProperty(typeof(SfDataGrid), "GridModel").GetValue(sfDataGrid, null);
var addNewRowController = ReflectionHelper.GetProperty(gridModel.GetType(), "AddNewRowController").GetValue(gridModel, null);
var commitAddNewMethod = ReflectionHelper.GetMethod(addNewRowController.GetType(), "CommitAddNew");
ReflectionHelper.Invoke(commitAddNewMethod, addNewRowController, new object[] { true });
rowColumnIndex.RowIndex = this.sfDataGrid.GetAddNewRowIndex();
this.sfDataGrid.SelectedItems.Clear();
if (this.sfDataGrid.AddNewRowPosition == RowPosition.Top)
rowColumnIndex.RowIndex = rowColumnIndex.RowIndex + 1;
this.sfDataGrid.MoveToCurrentCell(rowColumnIndex);
}
}
private void cancel_Click(object sender, EventArgs e)
{
if (this.sfDataGrid.View.IsAddingNew)
{
if (this.sfDataGrid.CurrentCell.IsEditing)
this.sfDataGrid.CurrentCell.EndEdit(true);
var gridModel = ReflectionHelper.GetProperty(typeof(SfDataGrid), "GridModel").GetValue(sfDataGrid, null);
var addNewRowController = ReflectionHelper.GetProperty(gridModel.GetType(), "AddNewRowController").GetValue(gridModel, null);
var cancelAddNewMethod = ReflectionHelper.GetMethod(addNewRowController.GetType(), "CancelAddNew");
ReflectionHelper.Invoke(cancelAddNewMethod, addNewRowController, new object[] { });
}
} |