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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Canceling an Add new row operation

Thread ID:

Created:

Updated:

Platform:

Replies:

121236 Nov 21,2015 12:04 AM UTC Nov 24,2015 11:23 AM UTC WPF 3
loading
Tags: SfDataGrid
Alessandro Del Sole
Asked On November 21, 2015 12:04 AM UTC

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

Sivakumar R [Syncfusion]
Replied On 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


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

Thank you, really helpful reply!
Alessandro

Sowndaiyan Paulpandi [Syncfusion]
Replied On 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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;