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.

I was wondering if there is a way I can code the TOC control so that I can select multiple layers and GROUP them together. So if i uncheck the group, all layers will be unchecked and be invisible.

Thanks and Regards, Kevin

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You probably need to do some coding, because I haven't seen anything similar to the ArcMap Group context menuitem in engine.

But you should be able to do this with a group layer.

One way would be to create a group layer and add the layers in the group layer instead of the map and add the group layer to the map. Don't forget to fire the ContentsChanged() on the Active View otherwise the Toc will not be refreshed and PartialRefresh(esriViewAll,Nothing,Nothing) to update the map.

An other way would be to move the layers to the newly created group layer, see the question rearrange layers. To find out the layers that get clicked you need to use the HitTest, check out the context menu sample on how to use hit testing.

share|improve this answer
    
Thanks, I'll give that group layer a try, i notice there is a "Group Layer" class in Engine too, but i didn't try because I can't get Engine 10 to support Multiple Selection in TOC, I don't think its supported, but i'll give that a try. –  Kev84 Mar 28 '11 at 14:02

Here is an ArcObjects example of how to turn on and off a group layer via the TOC ("pGroupLayer.Visible = True ").

        pMap = m_Mxdoc.FocusMap

        Dim pContentsView As IContentsView
        pContentsView = m_Mxdoc.CurrentContentsView

        For i = 0 To pMap.LayerCount - 1
            If pMap.Layer(i).Name = "My Layer" Then
                pLayer = pMap.Layer(i)
                If TypeOf pLayer Is IGroupLayer Then
                    pGroupLayer = pLayer
                    pContentsView.SelectedItem = pLayer
                    pGroupLayer.Visible = True

                    m_Mxdoc.UpdateContents()
                    m_Mxdoc.ActiveView.Refresh()

                End If
            End If
        Next i
share|improve this answer

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.