General information
Title:
TreeView control Conquered, I think...
I was having a lot of trouble with the Treeview control, until Nick gave me that all important hint.
The idea was to replicate an Explorer type interface using the control. For this I needed an function
that could read and replicate an entire Treeline onto another node. Typically the result of an
drag & drop operation. The function I came up with pleased me so much I decided to show to you all,
so that you may rip it apart. Have fun
*-----------------------------
*-- Code for pNodeMove Method
*-----------------------------
*poRefTrv: Reference to the Treeview object the node is dropped on
*poNode: Reference to the Treeview object the node is dropped on
*poTargetNode: : The node is dropped on, usually the result of an HitTest method
*-----------------------------
LPARAMETER poRefTrv, poNode, poTargetNode
IF TYPE( "poRefTrv") # "O" OR ISNULL( poRefTrv)
RETURN .F.
ENDIF
IF TYPE( "poNode") # "O" OR ISNULL( poNode)
RETURN .F.
ENDIF
IF TYPE( "poTargetNode") # "O" OR ISNULL( poTargetNode)
RETURN .F.
ENDIF
LOCAL llReturn, lloRef, lnCount ;
, laNode, lnAryCnt
IF ISNULL( poNode)
RETURN .F.
ENDIF
DIME laNode( 1, 4) && Parent key, node key, text, image
lnAryCnt = 0
loRef = poNode
lnAryCnt = lnAryCnt + 1
DIME laNode( lnAryCnt, 4)
laNode( lnAryCnt, 1) = poTargetNode.KEY
laNode( lnAryCnt, 2) = loRef.KEY
laNode( lnAryCnt, 3) = loRef.TEXT
laNode( lnAryCnt, 4) = loRef.IMAGE
oRoot = poRefTrv
lnCount = 1
DO WHILE .T.
loRef = oRoot.Nodes( laNode( lnCount, 2) ).CHILD
DO WHILE .T.
IF ISNULL( loRef)
EXIT
ELSE
lnAryCnt = lnAryCnt + 1
DIME laNode( lnAryCnt, 4)
laNode( lnAryCnt, 1) = loRef.PARENT.KEY
laNode( lnAryCnt, 2) = loRef.KEY
laNode( lnAryCnt, 3) = loRef.TEXT
laNode( lnAryCnt, 4) = loRef.IMAGE
ENDIF
loRef = loRef.NEXT
ENDDO
*-- Getting the Next variable in the Tree heiarchy
lnCount = lnCount + 1
IF lnCount > lnAryCnt
EXIT
ENDIF
ENDDO
lnCount = 0
lnMaxCount = 0
oRoot.Nodes.REMOVE( laNode( 1, 2) )
FOR lnCount = 1 TO ALEN( laNode, 1)
IF !ISNULL( oRoot.ImageList)
loRef = oRoot.Nodes.ADD( laNode( lnCount, 1), 4, laNode( lnCount, 2), laNode( lnCount, 3), laNode( lnCount, 4))
ELSE
loRef = oRoot.Nodes.ADD( laNode( lnCount, 1), 4, laNode( lnCount, 2), laNode( lnCount, 3))
ENDIF
loRef.EnsureVisible
ENDFOR
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only