Enable OLE drop of data in the MapControl


PurposeThis sample demonstrates dropping data dragged from ArcCatalog and Windows Explorer onto the MapControl. To enable data to be dropped onto the MapControl, the OleDropEnabled property is set to true, which allows the OnOleDrop event to trigger whenever data is dragged over the control.

When dragged data initially enters the MapControl, the OnOleDrop event is triggered with an esriDropEnter action. The IDataObjectHelper interface is used to determine whether the data is being dragged from ArcCatalog or Windows Explorer, using the CanGetNames and CanGetFiles methods. If the data is from ArcCatalog or Windows Explorer, the DragDropEffect is set to esriDragDropCopy; otherwise, it is set to esriDragDropNone. The DragDropEffect is then stored for later use.

When data is being dragged around the MapControl, the OnOleDrop event is triggered with an esriDropOver action. The DragDropEffect is set to the effect stored when the data initially entered the control and the mouse coordinates are updated on the form. The MapControl OnMouseMove event updates the coordinates on the form when the OnOleDrop event is not being triggered.

When data is dropped onto the MapControl, the OnOleDrop event is triggered with an esriDropped action. The IDataObjectHelper interface is used to obtain an array of file path strings from the data using the GetFiles method if the CanGetFiles method returns true; otherwise, an IEnumName collection is obtained using the GetNames method. The CheckMxFile method is used to determine whether each file path in the array is a valid Mx document. If valid, the LoadMxFile method is used to load the document into the MapControl; otherwise, a new IFileName object is created with its path property set to the file path in the array. The IFileName is used to create a layer that can be added to the MapControl in the same way that the INames obtained by enumerating the IEnumName collection do. (Note that Mx document and layer (.lyr) files if dropped from ArcCatalog, will return true for CanGetFiles, as they are both a type of IFileName).

The ILayerFactoryHelper interface is used to create a collection of ILayers using the CreateLayersFromName method. Each layer is added to the MapControl using the AddLayer method.

Development licensing Deployment licensing
Engine Developer Kit Engine Runtime
ArcView
ArcEditor
ArcInfo

How to use

See Using the samples for help on compiling, setting up the debugger, and running the sample (either an exe or dll).

  1. Drag and drop data files from ArcCatalog and Windows Explorer onto the MapControl.

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

Download the files for all languages

See Also:

MapControl class
IMapControl2 interface