We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Canceling an Add new row operation

Hi,
I handle the AddNewRowInitiating event to detect when the user is adding a new item to a SfDataGrid. Supposing I detect the item being added is invalid for some reasons, is there a way to programmatically cancel the insert operation?

Thanks in advance,
Alessandro

3 Replies

SR Sivakumar R Syncfusion Team November 23, 2015 03:57 AM UTC

Hi Alessandro,


You can validate the AddNewRow by handling RowValidating event of SfDataGrid. If you want to cancel the AddNew operation by validating, then you can use the below code to achieve your requirement,


using Syncfusion.UI.Xaml.Grid.Helpers;
this.dataGrid.RowValidating += dataGrid_RowValidating;

void dataGrid_RowValidating(object sender, RowValidatingEventArgs args)

{

    if (this.dataGrid.IsAddNewIndex(args.RowIndex))

    {

        //Code for cancelling AddNew operation by validating the args.RowData

        if (this.dataGrid.SelectionController.CurrentCellManager.CurrentCell.IsEditing)

            this.dataGrid.SelectionController.CurrentCellManager.EndEdit(true);

        var AddNewRowController = this.dataGrid.GetGridModel().AddNewRowController;

        AddNewRowController.CancelAddNew();

    }
}

Refer the below KB, if you are using below 13.3 version to reflect and cancel AddNew operation.
https://www.syncfusion.com/kb/5099/

Thanks,
Sivakumar



AD Alessandro Del Sole November 23, 2015 05:20 PM UTC

Thank you, really helpful reply!
Alessandro


SP Sowndaiyan Paulpandi Syncfusion Team November 24, 2015 11:23 AM UTC

Hi Alessandro,

Thanks for your update.

Please let us know if you need any other assistance.

Regards,

Sowndaiyan


Loader.
Up arrow icon