How to collapse a layer in the TOC programmatically

1826
1
03-09-2011 09:25 AM
ReneeCammarere
Occasional Contributor
In the following snippit of code, I am attempting to collapse a layer in the TOC.  However, this doesn't seem to be working. Is there a way to do that?

            IMap aMap = axMapControl1.ActiveView.FocusMap;
            ILayer pLayer = aMap.get_Layer(0);
            INALayer2 anNALyr = (INALayer2)pLayer;
            anNALyr.Expanded = false;
            axTOCControl1.Refresh();

Thanks!
Renee
0 Kudos
1 Reply
YaminiManickam
New Contributor III
The ILegendGroup.Visible property indicates whether or not a layer's entry in the table of contents is expanded or collapsed. If a layer has only one legend group, then if Visible = True, then the layer is expanded. If a layer has more than one legend group, then the rule is that if any of the the layer's legend groups are visible, then the layer's entry in the table of contents is expanded. For more information on the property, please check:

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//0012000007n3000000
0 Kudos