Hello,
Is there a way to commit a new row (or the edit of a previously existing row) when the SfDataGrid lost focus (for example to click a save button)?
Now the default behavior is that the row is only commit to the underlaying ItemsSource object when the row is finished (reaching the last cell in the row and pass to the new row) but sometimes the row doesn't need to have all the cells filled and is the last to add and a lost focus could validate and commit that row.
Is there a way to do this, maybe through the LostKeyboardFocus or a better approach to it?
Thanks in advance.
|
private void OnLostKeyBoardBehavior(object sender, KeyboardFocusChangedEventArgs e)
{
if (!this.sfDataGrid.IsKeyboardFocusWithin)
{
if (this.sfDataGrid.View != null && this.sfDataGrid.View.CurrentEditItem != null && !sfDataGrid.View.IsAddingNew)
{
// it commit the modified value in the grid.
this.sfDataGrid.View.CommitEdit();
}
if (this.sfDataGrid.View != null && this.sfDataGrid.View.IsAddingNew)
{
// it commit the entered value in the grid.
if (this.sfDataGrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing)
this.sfDataGrid.SelectionController.CurrentCellManager.EndEdit(true);
var addNewRowController = this.sfDataGrid.GetAddNewRowController();
addNewRowController.CommitAddNew();
}
}
} |
Thank you so much for the reply, That's exactly what I was looking for.