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

How to cancel an edit in the Pivot Grid - From 181633

I have another question, is it possible to cancel an edit in the Pivot Grid? e.g., validate that the user entered a reasonable number and restore the original value if not? Let me know if I should make a new forum post for this.

Thanks again,

Robert van der Leek


1 Reply 1 reply marked as answer

VS Vijayarasan Sivanandham Syncfusion Team April 10, 2023 02:17 PM UTC

Hi Robert van der Leek,

Your requirement to cancel an edit in the PivotGrid can be achieved by customizing the CurrentCellStartEditing and CurrentCellEditingComplete events in PivotGrid. Refer to the below code snippet,

//Event Handlers

pivotGridControl1.TableControl.CurrentCellStartEditing += OnCurrentCellStartEditing;

pivotGridControl1.TableControl.CurrentCellEditingComplete += OnCurrentCellEditingComplete;

 

 

// Maintain the cell value in the tempVariable

string tempVariable;

 

// Event handler for the CurrentCellStartEditing event

private void OnCurrentCellStartEditing(object sender, CancelEventArgs e)

{

    // Get the current cell

    var currentCell = pivotGridControl1.TableControl.CurrentCell;

 

    // Get the cell value and store it in the temp variable

    tempVariable = pivotGridControl1.TableModel[currentCell.RowIndex, currentCell.ColIndex].CellValue.ToString();

       

}

 

// Event handler for the CurrentCellEditingComplete event

private void OnCurrentCellEditingComplete(object sender, EventArgs e)

{

    // Get the current cell

    var currentCell = pivotGridControl1.TableControl.CurrentCell;

 

    // Customize the condition based on your requirement

    // Here validate that the user entered number and restore the original value (using tempVariable) if not satisfy the condition

    if (pivotGridControl1.TableModel[currentCell.RowIndex, currentCell.ColIndex].CellValue.ToString() == "4")

        // Restore the original value when the user entered value is 4

        pivotGridControl1.TableModel[currentCell.RowIndex, currentCell.ColIndex].CellValue = tempVariable;

}


Find the sample demo in the attachment.

Regards,

Vijayarasan S


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Attachment: PivotGridControl_c5c91d2f.zip

Marked as answer
Loader.
Live Chat Icon For mobile
Up arrow icon