Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

drag nodes within treeview

Status
Not open for further replies.

paloalto

Programmer
Joined
Nov 9, 2003
Messages
5
Location
CA
hi - i'm trying to drag/drop nodes within the same treeview control and can't get this to properly work, i've looked at what documentation i've found and isn't mentioned, any suggestions would be appreciated!
 
paloalto

Can you explain what your are trying to do? Drag and drop from where to where? Different nodes?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
yes, I want to allow the user to move nodes within the treeview; for example, to move a child node to a different parent. thanks.
 
just bringing to front again in hope of help.
 
Take a glance to HitTest and DropHighlight. If You need more help let me know
 
Essentially, when you start dragging, you have to note (using HitTest) which node it is that's being dragged, and use SetData to store that data in the OLE drag object.

Then, when you drop the OLE drag object (representing a node) on a node, you again need to use HitTest to determine what node it was dropped on.

Then ( if that drop location is allowed ) you have to delete the dragged node , and create a new one "inside" the one that was dropped on.


ie:
(this code is not "ready-to-run".. I cut and pasted a bunch of working code to put this together, but You should get the idea...)

On the Treeview:
Code:
OLEDragMode=1
OleDropMode=1
------------------------------
In MouseDown Event:
*** ActiveX Control Event ***
LPARAMETERS button, shift, x, y
loNode = THIS.HitTest( x*15,y*15 )
if VARTYPE(loNode)='O'
  THISFORM.NodeTapped = loNode.Key
else
  THISFORM.NodeTapped = ''
endif
loNode = .NULL.

------------------------------
In OLEStartDrag Event:
*** ActiveX Control Event ***
LPARAMETERS oData, allowedeffects
LOCAL loDragNode
IF VARTYPE(goOLESpy)<>'O'
  * frmDropTarget is my own form that will accept any ole-drag-drop
  *  and will just show the contents of what was dropped. 
  *  This is just for debugging
  RELEASE goOLESPY
  PUBLIC goOLESPY
  goOLESPY = NEWOBJECT('frmDropTarget','samplelex.vcx')
  goOLESPY.LEFT = _SCREEN.Width-goOLESPY.Width
  goOLESPY.TOP  = 0
  goOLESPY.Visible = .T.
endif

if vartype(THISFORM.NodeTapped)='C' && VarType(lcNodeKey)='O'
    
    goOLESPY.Edit1.Value = 'Dragging: '+THISFORM.NodeTapped

  * Data is pre-created with an OLEData object
  * We can determine what node is being dragged by THIS.SelectedItem/.Key
  oData.SetData( 'LEXTREENODE)'+THISFORM.NodeTapped, 1 )

  * Bit combination of:
  * 0 DROPEFFECT_NONE Drag source did not support any drag operations. 
  * 1 DROPEFFECT_COPY Drag source supports Copy operations. 
  * 2 DROPEFFECT_MOVE Drag source supports Move operations (the default). 
  * 4 DROPEFFECT_LINK Drag source supports link operations. 
  
  AllowedEffects = 3 && Move or Copy
else
  AllowedEffects = 0
endif
------------------------
In OLEDragOver Event:
*** ActiveX Control Event ***
LPARAMETERS oData, effect, button, shift, x, y, state
IF oData.GetFormat(1) && Has text describing it
   lcNodeKey = THIS.HitTest( x*15,y*15 )
   THIS.DropHighlight = THIS.HitTest(X*15,Y*15)
   if VarType(lcNodeKey)='O'
     lcNodeKey = lcNodeKey.Key
     if vartype(goOLESPY)='O'
       goOLESPY.Edit1.Value = 'DRAG OVER> '+lcNodeKey
     endif
     
     Effect = 2 && Move
     RETURN
     
* Here we need to determine whether the dragged node can be dropped here.
*      lcNodeKey is the node that it's being dropped on.
*     if NOT InList(upper(lcNodeKey),'SEA','LEA')
*       Effect = 2 && Move
*       RETURN
*     endif

   endif
   Effect = 0 && None
ENDIF
--------------------------------
In OleDragDrop Event:
*** ActiveX Control Event ***
LPARAMETERS oData, effect, button, shift, x, y
LOCAL lcNodeDropped, lcCatchingNode, loNodeDropped, loCatchingNode, ;
  lcNodeType, lcParentType, laType[1,5], lnTypes, laWrk[4], lnWrk, lnI
IF oData.GetFormat(1)
   THIS.DropHighlight = .NULL.
   * Here, we have to figure out what to do when this node is dropped on.
   lcNodeDropped  = oData.GetData(1)
   DO CASE
     CASE lcNodeDropped='LEXTREENODE)'
       *               1234567890123
       lcNodeDropped = SUBSTR(lcNodeDropped,13)
       
       loCatchingNode = THIS.HitTest( x*15,y*15 )
       if VarType(loCatchingNode)='O'
         lcCatchingNode = loCatchingNode.Key
------------------------
[/code]
 
thanks much Juris and wgcs, I'll give this a try and post again if problems.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top