Set Layer Index for Added Layer

420
0
12-06-2013 08:50 AM
DaveCouture
New Contributor III
Using VB.NET, how can I add a Layer at a certain position in the TOC? I'm able to add a layer, but I'm having trouble changing its index. In this example, I'm trying to send the added layer at the bottom of the TOC. The part in red is where I'm having trouble.


Dim pMap As IMap = My.ArcMap.Document.ActiveView
Dim lyr As ILayerFile = New LayerFile()
Dim parcels As String = "D:\Parcels.lyr"

If System.IO.File.Exists(parcels) Then
    lyr.Open(parcels)
    Dim pLayer As ILayer = lyr.Layer
    pMap.AddLayer(pLayer)
    pMap.setLayerIndex(pLayer, pMap.LayerCount + 1)
Else
    MsgBox(parcels + " cannot be found")
End If
0 Kudos
0 Replies