Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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
        Else
            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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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