We have a stand-alone application were we let the users add local shape and raster layers. We would like to add functionality so that the user can rearrange the added layers within a specific group layer.

We know it's possible to enable drag and drop on the TocControl but it lets the user rearrange all layers and that's not an option for us. Is there a way to enable drag and drop only on a specific group layer or somehow mimic the same behavior?

1 Answer 1


Not as visually cool but at least it work, use the MoveLayerEx in IMapLayers can be used to move a layer in a group layer, use the same grouplayer as source and target and apply the index that the layer shall have in the group. Made a small code sample:

Private Sub MoveGroupLayerItem(ByVal up As Boolean)
        Dim layer As ILayer = getLayer()
        Dim layerIndex As Integer = getLayerGroupIndex()

        Dim map As IMap = axMapControl1.ActiveView.FocusMap

        Dim mapLayers As IMapLayers = CType(map, IMapLayers)

        Dim groupLayer As IGroupLayer = CType(map.Layer(0), IGroupLayer)
        Dim compLayer As ICompositeLayer = CType(groupLayer, ICompositeLayer)

        If up Then
            If layerIndex > 0 Then
                mapLayers.MoveLayerEx(groupLayer, groupLayer, layer, layerIndex - 1)
            End If
            If (layerIndex < compLayer.Count - 1) Then
                mapLayers.MoveLayerEx(groupLayer, groupLayer, layer, layerIndex + 1)
            End If
        End If

        axMapControl1.Refresh(esriViewDrawPhase.esriViewAll, Nothing, Nothing)
    End Sub

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.