Programmatically contract the legend for a raster layer in the ArcMap Table of Contents

Last Published: April 25, 2020


This sample code shows how to programmatically contract the legend for a raster layer using ArcObjects.


Set the ILegendGroup Visible property to False to contract the legend in the Table of Contents (TOC).

Sub RasterRend()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap

Dim pLayer As IRasterLayer
Set pLayer = pMap.Layer(0)

Dim pRend As IRasterRenderer
Set pRend = pLayer.Renderer
Dim pLegInfo As ILegendInfo
Set pLegInfo = pRend
Dim pLegGroup As ILegendGroup
Set pLegGroup = pLegInfo.LegendGroup(0)
pLegGroup.Visible = False

End Sub

Article ID:000004813

  • ArcMap 8 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options