ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapTool Class / ActivateSelectAsync Method
If True the tool will start selecting features.
Example

In This Topic
    ActivateSelectAsync Method
    In This Topic
    Sets the tool into or out of selection mode. Only supported when SketchType is set to Point, Line, Polygon, or Multipoint.
    Syntax
    protected Task<bool> ActivateSelectAsync( 
       bool activate
    )
    Protected Function ActivateSelectAsync( _
       ByVal activate As Boolean _
    ) As Task(Of Boolean)

    Parameters

    activate
    If True the tool will start selecting features.

    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
    //UseSelection = true; (UseSelection must be set to true in the tool constructor or tool activate)
    private bool _inSelMode = false;
    
    public bool IsShiftKey(MapViewKeyEventArgs k)
    {
      return (k.Key == System.Windows.Input.Key.LeftShift ||
             k.Key == System.Windows.Input.Key.RightShift);
    }
    
    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);
      }
    }
    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);
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also