ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapTool Class / ActivateSelectAsync Method
If True the tool will change into select mode. If false, the tool will change into sketch mode.
Example

In This Topic
    ActivateSelectAsync Method
    In This Topic
    Toggles the tool between sketch and selection modes. Only supported when SketchType is set to Point, Line, Polygon, or Multipoint.
    Syntax
    Protected Function ActivateSelectAsync( _
       ByVal activate As Boolean _
    ) As Task(Of Boolean)
    protected Task<bool> ActivateSelectAsync( 
       bool activate
    )

    Parameters

    activate
    If True the tool will change into select mode. If false, the tool will change into sketch mode.

    Return Value

    A Task representing the mode change operation. Returns false if the SketchType is unsupported.
    Remarks
    To save the sketch state while in selection mode, set UseSelection to True before entering selection mode.
    Example
    Toggle sketch selection mode
    /// <summary>
    /// Handles key down events for the tool, enabling or toggling sketch selection mode when specific keys are pressed.
    /// </summary>
    protected override async void OnToolKeyDown(MapViewKeyEventArgs k)
    {
      //toggle sketch selection mode with a custom key
      if (k.Key == System.Windows.Input.Key.W)
      {
        if (!_inSelMode)
        {
          k.Handled = true;
    
          // Toggle the tool to select mode.
          //  The sketch is saved if UseSelection = true;
          if (await ActivateSelectAsync(true))
            _inSelMode = true;
        }
      }
      else if (!_inSelMode)
      {
        //disable effect of Shift in the base class.
        //Mark the key event as handled to prevent further processing
        k.Handled = IsShiftKey(k);
      }
    }
    /// <summary>
    /// Handles the key up events for the tool, toggling sketch selection mode off when the W key is released.
    /// </summary>
    protected override void OnToolKeyUp(MapViewKeyEventArgs k)
    {
      if (k.Key == System.Windows.Input.Key.W)
      {
        if (_inSelMode)
        {
          _inSelMode = false;
          k.Handled = true;//process this one
    
          // Toggle back to sketch mode. If UseSelection = true
          //   the sketch will be restored
          ActivateSelectAsync(false);
        }
      }
      else if (_inSelMode)
      {
        //disable effect of Shift in the base class.
        //Mark the key event as handled to prevent further processing
        k.Handled = IsShiftKey(k);
      }
    }//UseSelection = true; (UseSelection must be set to true in the tool constructor or tool activate)
    private bool _inSelMode = false;
    
    private bool IsShiftKey(MapViewKeyEventArgs k)
    {
      return k.Key == System.Windows.Input.Key.LeftShift ||
             k.Key == System.Windows.Input.Key.RightShift;
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also