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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error In treeview Contol

Status
Not open for further replies.

progfox

Programmer
Jun 15, 2003
43
IN
Sir,

I am facing Problem form last few days regarding the tree-view control. As soon as the form runs for the first time, No error occurs but as the form is refreshed then error comes in as "OLE Exception Code 0 from Nodes: Key is not unique in the collection".


Sir I want to ask why the error occurs and pls provide me the solution to get rid form the error.

Thanks & Regards

Chandan
 
Thanx for ur kind attention gentlemen

I will try this out and let U know if the error has been cured or not


Regards


Chandan
 
FYI: I often will construct node Keys using first the Key I want to use, then appending SYS(2015) to the end.

This is important to me because I'm usually going from the node key in the tree to determine the context of actions... not the other way around... plus in my case the same node can show up in multiple branches of the tree.

I wrote these methods for my base TreeView class, you may find useful:
Code:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top