ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Editing.Events Namespace / RowChangedEventArgs Class / CancelEdit Method / CancelEdit(String,Boolean) Method
Example Version

CancelEdit(String,Boolean) Method
Cancel the current EditOperation with an option to override.
Syntax
public void CancelEdit( 
   string errorMessage,
   bool canOverride
)

Parameters

errorMessage
canOverride
Remarks
This method is used internally by workflow manager during feature creation. A dialog is always displayed with a fixed title. The override determines if the user can override the cancel.
Example
Cancel a delete
public void StopADelete()
{
  // subscribe to the RowDeletedEvent for the appropriate table
  Table table = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable();
  RowDeletedEvent.Subscribe(OnRowDeletedEvent, table);
}

private Guid _currentRowDeletedGuid = Guid.Empty;
private void OnRowDeletedEvent(RowChangedEventArgs args)
{
  // RowEvent callbacks are always called on the QueuedTask so there is no need 
  // to wrap your code within a QueuedTask.Run lambda.

  var row = args.Row;

  // check for re-entry 
  if (_currentRowDeletedGuid == args.Guid)
    return;

  // cancel the delete if the feature is in Police District 5
  var fldIdx = row.FindField("POLICE_DISTRICT");
  if (fldIdx != -1)
  {
    var value = row[fldIdx].ToString();
    if (value == "5")
    {
      //cancel with dialog
      // Note - feature edits on Hosted and Standard Feature Services cannot be cancelled.
      args.CancelEdit("Delete Event\nAre you sure", true);

      // or cancel without a dialog
      // args.CancelEdit();
    }
  }
  _currentRowDeletedGuid = args.Guid;
}
Cancel a delete
public void StopADelete()
{
  // subscribe to the RowDeletedEvent for the appropriate table
  Table table = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault().GetTable();
  RowDeletedEvent.Subscribe(OnRowDeletedEvent, table);
}

private Guid _currentRowDeletedGuid = Guid.Empty;
private void OnRowDeletedEvent(RowChangedEventArgs args)
{
  // RowEvent callbacks are always called on the QueuedTask so there is no need 
  // to wrap your code within a QueuedTask.Run lambda.

  var row = args.Row;

  // check for re-entry 
  if (_currentRowDeletedGuid == args.Guid)
    return;

  // cancel the delete if the feature is in Police District 5
  var fldIdx = row.FindField("POLICE_DISTRICT");
  if (fldIdx != -1)
  {
    var value = row[fldIdx].ToString();
    if (value == "5")
    {
      //cancel with dialog
      // Note - feature edits on Hosted and Standard Feature Services cannot be cancelled.
      args.CancelEdit("Delete Event\nAre you sure", true);

      // or cancel without a dialog
      // args.CancelEdit();
    }
  }
  _currentRowDeletedGuid = args.Guid;
}
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also