This document is archived and information here might be outdated.  Recommended version.


IMapControl2.AddLayer Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Controls > ESRI ArcGIS Controls > Interfaces > IM > IMapControl2 Interface > IMapControl2.AddLayer Method
ArcGIS Developer Help

IMapControl2.AddLayer Method

Adds a layer to the Map's collection of layers at the specified index position.

[Visual Basic .NET]
Public Sub AddLayer ( _
    ByVal Layer As ILayer, _
    [ByVal toIndex As Integer] _
)
[C#]
public void AddLayer (
    ILayer Layer,
    int toIndex
);
[C++]
HRESULT AddLayer(
  ILayer* Layer,
  long toIndex
);
[C++]
Parameters
Layer [in]

Layer is a parameter of type ILayer* toIndex [in, optional, defaultvalue()]
toIndex is a parameter of type long

Product Availability

Available with ArcGIS Engine.

Description

When a Layer is added to the MapControl's layer collection and no index is specified, it is added to the beginning or top of the collection with an index of 0. The numeric index of any other layers in the layer collection increments by one.

When a Layer is added and an index is specified, the numeric index of any other layers in the layer collection will increment by one, except for those layers with an index less than the specified index. The index of these layers will remain the same.

Errors Returned

1023 800a03ff: The specified index is out of range

Remarks

The Layer at the beginning or top of the collection with an index of 0 will be drawn last, whilst the Layer at the bottom of the collection will be drawn first.

Use the MoveLayerTo method to change the position of a Layer within the layer collection.

See Also

IMapControl2 Interface | IMapControl4.AddLayerFromFile Method | IMapControl2.AddLayerFromFile Method | IMapControl3.AddLayerFromFile Method | IMapControl3.AddShapeFile Method | IMapControl2.AddShapeFile Method | IMapControl4.AddShapeFile Method