Tips_gui   >   Treelists   >   Treelist Events
There are a number of events related to treelists. You can trap them in the $event method of the Treelist.
Every one of the evTree... events has the parameter pNoteItem which is an item reference to the node.
The evTreeListEdit... events also have the parameter pColumnNumber indiciating the column number where the event is taking place.
The evTreeNodeNameFinishing and evTreeNodeName... events have also have the parameter pNewText which is the text which the user has entered.You can allow drag and drop nodes between treelists or within the same treelist. There are several treelist object properties you need to set in order to be able to do drag and drop operations. Set the treelist object
> tab properties are as follows:There is a demo included with this tip. Click the
button in the to open the demo window. The sample code below is used in the demo window.The $event method of the treelist object is as follows:
; $event method of a treelist object,.
On evDrop
; Get the visible node where the user dropped onto, and the previous node.
Calculate VisLineNum as mouseover(kMLine)
Do $cobj.$getvisiblenode(VisLineNum) Returns rDropNode
Do $cobj.$getvisiblenode(VisLineNum-1) Returns rPrevVisNode
; Get the selected nodes.
Do pDragField.$getselectednodes(List)
If pDragField.$objtype=kTreeList
; Add the selected nodes to the treelist.
Do method addSelectedNodes (List,rDropNode,rPrevVisNode) Returns AddedNodesList
; If the drag is coming from the same treelist remove the selected nodes.
If pDragField=$cobj
; Remove the old nodes.
For List.$line from 1 to List.$linecount step 1
Do $cobj.$remove(List.C1)
End For
End If
; Reset the current node to be the first added node.
Do $cobj.$setcurrentnode(AddedNodesList.1.C1)
; Get the list of nodes selected in the target list.
Do $cobj.$getselectednodes(List)
; Deselect any selected nodes in the target list.
For List.$line from 1 to List.$linecount step 1
Do List.C1.$multipleselect.$assign(kFalse)
End For
; Select the added nodes.
For AddedNodesList.$line from 1 to AddedNodesList.$linecount step 1
Do AddedNodesList.C1.$multipleselect.$assign(kTrue)
End For
End If
The addSelectedNodes method which is called by the $event method is as follows:
; Method: addSelectedNodes(pSelectedNodesList,prDropNode,prPrevVisNode)
; Define the NewNodesList
Do NewNodesList.$cols.$add('noderef',kItemref)
If prDropNode.$level=prPrevVisNode.$level-1
; The drop took place just after the last child node of the previous parent.
; Set the parent node to be the previous node's parent.
Do prPrevVisNode.$nodeparent() Returns rParentNode
; Add the dropped nodes after the previous node.
For pSelectedNodesList.$line from pSelectedNodesList.$linecount to 1 step -1
Set reference rNode to pSelectedNodesList.C1
Do rParentNode.$addafter(prPrevVisNode,rNode().$name) Returns rAddNode
Do NewNodesList.$add(rAddNode)
End For
Else
If prDropNode.$level=1 ;; Root node drop.
; Set the treelist object as the parent node.
Set reference rParentNode to $cobj
Else
; Set the parent node.
Do prDropNode.$nodeparent() Returns rParentNode
End If
; Loop through the list backwards, adding nodes before the drop node.
For pSelectedNodesList.$line from 1 to pSelectedNodesList.$linecount step 1
Set reference rNode to pSelectedNodesList.C1
Do rParentNode.$addbefore(prDropNode,rNode().$name) Returns rAddNode
Do NewNodesList.$add(rAddNode)
End For
End If
Quit method NewNodesList