ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Core Namespace / Project Class / SetIsEditingEnabledAsync Method
Example

In This Topic
    SetIsEditingEnabledAsync Method
    In This Topic
    Sets a value that indicates if editing is to be enabled or disabled within the application.
    Syntax
    public Task<bool> SetIsEditingEnabledAsync( 
       bool value
    )
    Public Function SetIsEditingEnabledAsync( _
       ByVal value As Boolean _
    ) As Task(Of Boolean)

    Parameters

    value

    Return Value

    A task representing a value indicating if the method was successful.
    Remarks
    Use this method to enable or disable editing within the application. Setting this value is independent of the visibility of the Enable/Disable editing control on the Edit Tab. If the project has unsaved edits, setting this value to false will not succeed, those edits must be saved or discarded first. Use the ArcGIS.Desktop.Core.Project.IsEditingEnabled property to determine if editing is enabled or disabled within the application.
    Example
    Enable Editing
    // if not editing
    if (!Project.Current.IsEditingEnabled)
    {
      var res = MessageBox.Show("You must enable editing to use editing tools. Would you like to enable editing?",
                                                            "Enable Editing?", System.Windows.MessageBoxButton.YesNoCancel);
      if (res == System.Windows.MessageBoxResult.No ||
                    res == System.Windows.MessageBoxResult.Cancel)
      {
        return;
      }
      Project.Current.SetIsEditingEnabledAsync(true);
    }
    
    Disable Editing
    // if editing
    if (Project.Current.IsEditingEnabled)
    {
      var res = MessageBox.Show("Do you want to disable editing? Editing tools will be disabled",
                                                             "Disable Editing?", System.Windows.MessageBoxButton.YesNoCancel);
      if (res == System.Windows.MessageBoxResult.No ||
                    res == System.Windows.MessageBoxResult.Cancel)
      {
        return;
      }
    
      //we must check for edits
      if (Project.Current.HasEdits)
      {
        res = MessageBox.Show("Save edits?", "Save Edits?", System.Windows.MessageBoxButton.YesNoCancel);
        if (res == System.Windows.MessageBoxResult.Cancel)
          return;
        else if (res == System.Windows.MessageBoxResult.No)
          Project.Current.DiscardEditsAsync();
        else
        {
          Project.Current.SaveEditsAsync();
        }
      }
      Project.Current.SetIsEditingEnabledAsync(false);
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also