ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapView Class / SelectLayers Method
Example

In This Topic
    SelectLayers Method
    In This Topic
    Selects layers in the TOC.
    Syntax
    public void SelectLayers( 
       IReadOnlyCollection<Layer> layers
    )
    Public Sub SelectLayers( _
       ByVal layers As IReadOnlyCollection(Of Layer) _
    ) 

    Parameters

    layers
    Example
    Select all feature layers in TOC
    public void SelectAllFeatureLayersInTOC()
    {
      //Get the active map view.
      var mapView = MapView.Active;
      if (mapView == null)
        return;
    
      //Zoom to the selected layers in the TOC
      var featureLayers = mapView.Map.Layers.OfType<FeatureLayer>();
      mapView.SelectLayers(featureLayers.ToList());
    }
    
    Select a layer and open its layer properties page
    // get the layer you want
    var layer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().FirstOrDefault();
    
    // select it in the TOC
    List<Layer> layersToSelect = new List<Layer>();
    layersToSelect.Add(layer);
    MapView.Active.SelectLayers(layersToSelect);
    
    // now execute the layer properties command
    var wrapper = FrameworkApplication.GetPlugInWrapper("esri_mapping_selectedLayerPropertiesButton");
    var command = wrapper as ICommand;
    if (command == null)
      return;
    
    // execute the command
    if (command.CanExecute(null))
      command.Execute(null);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also