ArcObjects Component Help  (Core)    

IMapControl2.AddLayerFromFile Method

Loads a layer file and adds it to the Map's collection of layers at the specified index position.

[Visual Basic 6.0]
Sub AddLayerFromFile(
    ByVal lyrPath As String, _
    [ByVal toIndex As Long] _
) As Empty
[Visual Basic .NET]
Public Sub AddLayerFromFile (
    ByVal lyrPath As String, _
    ByVal toIndex As Integer _
)
[C#]
public void AddLayerFromFile (
    string lyrPath,
    int toIndex
);
[C++]
public: void AddLayerFromFile (
    String* lyrPath,
    int toIndex
);

Description

When a layer file 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.

MapControl1.AddLayerFromFile "C:\Temp\myLayer.lyr"

When a layer file 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.

MapControl1.AddLayerFromFile "C:\Temp\myLayer.lyr", 2

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.

MapControl1.Layer (0)  'Last layer to draw
MapControl1.Layer (1)  'Second from last layer to draw
MapControl1.Layer (MapControl1.LayerCount - 1 ) 'First layer to draw

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

See Also

IMapControl2.AddLayer Method | IMapControl2.AddShapeFile Method