This document is archived and information here might be outdated.  Recommended version.


Using the TOCControl (ArcObjects .NET 10.4 SDK)

Using the TOCControl


In this topic


About using the TOCControl

The TOCControl (table of contents control) works in conjunction with a buddy control, displaying the maps, layers, and symbology that are contained in the buddy. The buddy control can be a MapControl, PageLayoutControl, GlobeControl, or SceneControl. The buddy control can be set at design time through the TOCControl property pages (in development environments that support property page capability) or programmatically using the SetBuddyControl method when the container hosting the TOCControl is displayed. See the following screen shot:
See the following code example:
[C#]
axTOCControl1.SetBuddyControl(axMapControl1);
[VB.NET]
AxTOCControl1.SetBuddyControl(AxMapControl1)
Each TOCControl buddy control implements the ITOCBuddy interface and can fire methods on the ITOCBuddyEvents interface. The TOCControl uses the buddy control to display an interactive Catalog tree of its map, layer, and symbology contents and to keep its contents synchronized with the buddy control. For example, if the TOCControl has a MapControl as its buddy, and a map layer is removed from the MapControl, the map layer is also removed from the TOCControl. Likewise, if the end user interacts with the TOCControl to clear a map layer's visibility check box, the layer will not be visible in the MapControl.
Each layer's check box in the TOCControl is displayed in one of the following ways, depending on the state of the layer:
Visibility check box
Description
A layer that is visible.
A layer that is not visible.
A layer that is visible at certain scales (2D) or altitudes (3D).
A broken layer whose data cannot be displayed.

Layer drag and drop

The TOCControl supports the dragging and dropping of layers in the control when the ITOCControl2.EnableLayerDragDrop property is set. Layers can be moved or copied (by pressing the Ctrl key) in the following ways:
  • Within a map
  • To and from group layers
  • Between maps
  • Between maps in different TOCControls
  • From ArcMap

Selected item

An item can be selected in the TOCControl interactively by the end user clicking the TOCControl or programmatically using the ITOCControl2.SelectItem method. The ITOCControl2.GetSelectedItem method returns the selected item. See the following code example:
[C#]
IBasicMap map=new MapClass();
ILayer layer=new FeatureLayerClass();
object legendGroup=new object();
object index=new object();
esriTOCControlItem item=new esriTOCControlItem();

axTOCControl1.GetSelectedItem(ref item, ref map, ref layer, ref legendGroup, ref
    index);
if (item == esriTOCControlItem.esriTOCControlItemLayer)
    System.Windows.Forms.MessageBox.Show("Map: " + map.Name + " Layer: " +
        layer.Name);
[VB.NET]
Dim map As IMap, layer As ILayer, legendGroup As Object
Dim index As Object, Item As esriTOCControlItem
map=New MapClass
layer=New FeatureLayerClass
legendGroup=New Object
index=New Object
Item=New esriTOCControlItem

AxTOCControl1.GetSelectedItem(Item, map, layer, legendGroup, index)
If Item=esriTOCControlItem.esriTOCControlItemLayer Then System.Windows.Forms.MessageBox.Show("Map: " & map.Name & " Layer: " & layer.Name)


See Also:

Controls library overview
Sample: Displaying a TOCControl context menu
Sample: Enable layer drag and drop in the TOCControl
Disabling or validating label edits in the TOCControl
Sample: TOCControl metadata viewer




Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced