PROCEDURE NodeClick
*** ActiveX Control Event ***
LPARAMETERS node && as mscomctllib.Node
IF node.Selected
IF Type(THIS.vfpControlSource)='C'
LOCAL lcVar
lcVar = THIS.vfpControlSource
&lcVar = Node.Key
ENDIF
ENDIF
ENDPROC
PROCEDURE FindNode
PARAMETER pcNodeText, pNode
* Find a node based on the caption text...
* According to FoxTalk June 1999, The treeview control doesn't work
* in VFP 5/6 if you use the same variable NAME to store more than
* node (consecutively). Internal housekeeping in VFP must mess up.
* So we need to create a new variable for each Node we want to store.
LOCAL lNode
lNode = sys(2015) && Unique Name
LOCAL &lNode
if Parameters()>1
* Search this sub-tree
if type("pNode")="O" and NOT isNull(pNode)
&lNode = pNode
else
RETURN .F.
endif
else
* Start at the root!
if type("this.nodes[1].root")="O" ;
and NOT isNull(this.nodes[1].root)
&lNode = this.nodes[1].root
else
RETURN .F.
endif
endif
do while Not IsNull( eval(lNode) )
if upper(alltrim(&lNode..Text)) = upper(alltrim(pcNodeText))
&lNode..Expanded = .T.
&lNode..Selected = .T.
THIS.nodeclick( &lNode. )
RETURN .T.
else
if !IsNull( &lNode..child )
if this.FindNode( pcNodeText, &lNode..Child )
&lNode..Expanded = .T.
RETURN .T.
endif
endif
endif
lNode2 = sys(2015) && Unique Name
LOCAL &lNode2
&lNode2 = &lNode..Next
lNode = lNode2
enddo
do case
case type("pNode")="O" and NOT isNull(pNode)
* Not found in this sub-tree
RETURN .F.
case type("this.nodes[1].root")="O" ;
and NOT isNull(this.nodes[1].root)
* Never Found.. This is the root (MASTER), activate it!
THIS.nodeclick( THIS.Nodes[1].root )
endcase
RETURN .F.
ENDPROC
PROCEDURE IndexOf
LParameters lcKey
* Find a node based on it's key
* This is slower than using THIS.Nodes(lcKey)
* but this function won't throw any error.
local Indx
for indx = 1 to this.nodes.count
if alltrim(this.nodes.item[indx].Key)==alltrim(lcKey)
return Indx
endif
endfor
return -1
ENDPROC
PROCEDURE NodeExists
LPARAMETERS pcNodeKey
LOCAL loNode
THIS.Errored = .F.
* This next line throws an error if the key doesn't exist:
loNode = THIS.Nodes(pcNodeKey)
IF Type('loNode')='O' and not IsNull(loNode) ;
and not THIS.Errored
llRet = .T.
ELSE
llRet = .F.
ENDIF
THIS.Errored = .F.
loNode = ''
RETURN llRet
ENDPROC
PROCEDURE Error
LPARAMETERS nError, cMethod, nLine
* Trap any errors thrown by NodeExists
IF nError=1429 and 'ELEMENT NOT FOUND' $ Upper(Message())
THIS.Errored = .T.
ELSE
DoDefault(nError,cMethod,nLine)
ENDIF
ENDPROC