Drag and Drop between Tree controls

Environment: VC6 SP2, NT4 SP5

This article demonstrates drag and drop between tree controls using OLE Drag and Drop. It also allows an item to be dropped on same tree control.When an item is dropped all the children of that item are also dropped on the target. The following key combination can be used:

  • Left button, to copy an item
  • Ctrl+Left Button,to copy an item
  • Shift+Left Button,to move an item

There are two classes :

  • CDragDropTreeCtrl, for Tree control. This class also has a helper function AddItem() for adding an item to the tree control.
  • CTreeDropTarget, which provides functionality of Drop target

The CDragDropTreeCtrl registers the tree control as the drop target and starts the drag operation in respose to the TVN_BEGINDRAG message.

The CTreeDropTarget is derived from COleDropTarget and serves as drop target. This class overides the following functions:

  • OnDragEnter().
  • OnDragOver(). This function highlights and expands the item under the mouse pointer and also scrolls the tree control appropriately
  • OnDrop(). This function creates the item being dragged in the destination tree control when the user releases the mouse button.
What you have to do You need to do the following things:
  • #include afxole.h in stdafx.h
  • Call AfxOleInit() in InitInstance().
  • Create an object of CDragDropTreeCtrl in your class.

Downloads

Download demo project - 18 Kb
Download source - 5 Kb


Comments

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

  • Live Event Date: April 22, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Database professionals — whether developers or DBAs — can often save valuable time by learning to get the most from their new or existing productivity tools. Whether you're responsible for managing database projects, performing database health checks and reporting, analyzing code, or measuring software engineering metrics, it's likely you're not taking advantage of some of the lesser-known features of Toad from Dell. Attend this live …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds