Drop Files

Created:20/11/2001
Description:

This 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 ArcCataolg 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 IName's obtained by enumerating the IEnumName collection do. (Note that Mx document and layer files (.lyr) 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 ILayer's using the CreateLayersFromName method. Each layer is added to the MapControl using the AddLayer method.



How to use:
  1. Either run the DropFiles.exe or open the DropFiles.vbp and run from within the project.
  2. Drag and drop data files from ArcCatalog and Windows Explorer onto the MapControl. What happens if data is dragged from another appplication or File Dropping is disabled?

Application:
Map Control

Minimum ArcGIS Version Required: 8.2

Difficulty: Beginner


Visual Basic
File Description
DropFiles.frm VB form file for the DropFiles project.
DropFiles.frx VB Binary file.
DropFiles.vbp VB Project file.


Key CoClasses: MapControl
Key Interfaces: IDataObjectHelper, IEnumLayer, IEnumName, IFileName, ILayer, ILayerFactoryHelper, IName
Key Members: AddLayer, CheckMxFile, ClearLayers, LoadMxFile, MousePointer, OleDropEnabled