How to hide the symbols list in TOC control after creating layer layer

1635
3
05-30-2012 12:06 AM
AnatoliiTerentiev
Occasional Contributor III
After creating new layer and adding this layer to activeView,
in TOC control I see all symbols created. How I can hide the list of symbols?
Thanks in advance!
0 Kudos
3 Replies
RichWawrzonek
Occasional Contributor
You can collapse the legend for a feature layer in the TOC by using the ILegendInfo interface.

Assuming you have a pointer to a valid feature layer in the TOC called 'layer', here is a C# example:

ILegendInfo legendInfo = (ILegendInfo) layer; 
legendInfo.get_LegendGroup(0).Visible = false; //COLLAPSE THE LEGEND


You may need to modify the index number depending on the properties of your layer.
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
Can't collapse layer, picture attached. Code:
 
      addLayerFromShapeFile(shapefileLocation, имяСлоя);
      featureLayer = getLayerByName(имяСлоя) as ESRI.ArcGIS.Carto.IFeatureLayer;
      geoFeatureLayer = (IGeoFeatureLayer)featureLayer;
      geoFeatureLayer.Renderer = getRenderer(имяСлоя);
      ILegendInfo legendInfo = (ILegendInfo)featureLayer;
      legendInfo.get_LegendGroup(0).Visible = false; //COLLAPSE THE LEGEND

In debugger I see
  
legendInfo.LegendGroupCount = 148

What is wrong?
0 Kudos
AnatoliiTerentiev
Occasional Contributor III
If at least 1 legend group is visible, layer is expanded.
I solved problem by adding
 
for (int k = 0; k < legendInfo.LegendGroupCount; k++)           
      legendInfo.get_LegendGroup(k).Visible = false;
0 Kudos