Drag Drop Using OLE - April 1999

Steve Hoag wrote an article which was published in the March/April 1999 [Volume 8, Number 2] of MSDN News describing how to implement OLE drag and drop. I used the article as a guide while developing a demonstration program to show the code needed to implement the concepts. This demo becomes the tip-of-the-month.

The Demo Program

The demo program consists of one MDI form and two child forms. Dragging and dropping between list boxes is shown using one child form. Dragging and dropping between picture boxes is shown in the other child form. Use the mouse to drag one element to the other.

MDI and Two Child Forms

Preserve ItemData

I usually store a long variable in each list box item's ItemData property. OLE drag and drop does not 'copy' the ItemData property. I added code to the drag/drop routines to also copy ItemData. Click anywhere on the list box form to see 'debug' results of preserved ItemData. For example:

Debug ItemData Results

Drag Drop List Box Items

Debug Results

Copy Picture Using Any Shift Key

Make a copy of a picture by holding down any control key [Shift, Alt or Ctrl] and drag the picture using the mouse. (I tried using the left/right mouse button combination to copy or move. I think there may be a bug in the DragDrop routines. The Button property always returned zero. I could not distinguish between the left/right button.) A sample result:

Copied License Plate

Use the 'Reset the Pictures' command button to 'refresh' the pictures after you have moved or copied them.

Demo Code Revised December 2, 1999

It was possible for the user to attempt to drag a picture from a picture box that no longer contained a picture. This was corrected on December 2, 1999 by storing "N" in the picture's tag property if the picture is removed. The tag is check before allowing the drag operation to start.

Download VB Code

Click here to download the VB 6 Source Code [30k].

Previous Tip   Tip Index   Next Tip


Updated 2000/10/29