Enable layer drag and drop in the TOCControl


Purpose
This sample shows how to drag and drop layers in the TOCControl. The sample uses the TOCControl in conjunction with the PageLayoutControl and the controls commands. The ITOCControl2.EnableLayerDragDrop property is used to enable layer dragging and dropping. Once enabled, layers can be dragged and dropped as follows:
  • On a map 
  • On, to, and from a group layer
  • Between maps
  • Between maps in different TOCControls
  • In ArcMap
To copy a layer, instead of moving within a map, press the Ctrl key while dragging and dropping. To move a layer, instead of copying it between maps, press the Ctrl key while dragging and dropping.

How to use

See How to use ArcGIS samples for help on compiling, setting up the debugger, and running the sample. If the sample has associated data, you will find that the sample's zip file includes a "data" folder alongside the language folders. However, you will need to update the sample to point to the location of the data once you have extracted all the files.

  1. Load a map document into the PageLayoutControl and enable layer drag and drop.
  2. Re-order the layers in the TOCControl.
  3. Right-click the PageLayoutControl and drag a rectangle to create a MapFrame.
  4. Copy a layer into the new map by dragging and dropping a layer.
  5. Move a layer into the new map by dragging and dropping a layer while pressing the Ctrl key.

AssemblyInfo.cs Assembly information.
LayerDragDrop.cs Form file.
Download the C# files
AssemblyInfo.vb Assembly information.
LayerDragDrop.vb Form file.
Download the VB.NET files

Download the files for all languages

See Also:

TOCControl class
ITOCControl2 interface




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