ArcObjects Library Reference  (ArcMapUI)    

IMxDocument.SelectedLayer Property

The selected layer in the layer control.

[Visual Basic 6.0]
Property SelectedLayer As ILayer
[Visual Basic .NET]
Public ReadOnly Property SelectedLayer As ILayer
[C#]
public ILayer SelectedLayer {get;}

Product Availability

Available with ArcGIS Desktop.

Remarks

Returns the currently selected layer in the table of contents.

To select a layer in the table of contents, obtain an IContentsView reference via IMxDocument::ContentsView, then use either IContentsView::AddToSelectedItems or IContentsView::SelectedItem. To learn more, read the help for IContentsView.

[Visual Basic 6.0]

The following simple VBA subroutine checks to see if the selected layer is a group layer or a feature layer.

Public Sub CheckSelectedLayer()

    Dim pMxDocument As IMxDocument
    Set pMxDocument = Application.Document
    Dim pLayer As ILayer
    Set pLayer = pMxDocument.SelectedLayer
   
    If TypeOf pLayer Is IGroupLayer Then
        ' we have a group layer (GroupLayer)
        MsgBox pLayer.Name
    ElseIf TypeOf pLayer Is IGeoFeatureLayer Then
        ' we have a feature layer
        MsgBox pLayer.Name
    End If End Sub

See Also

IMxDocument Interface

 


Feedback Send feedback on this page