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
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
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.
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