FUNCTION AddChildren LPARAMETERS tcParent LOCAL lnOldRec m.lnOldRec = RECNO() &&Save current record SCAN FOR ALLTRIM(crelative) == m.tcParent o.Add(alltrim(crelative),4,alltrim(ckey), alltrim(ctext),0) AddChildren(alltrim(ckey)) ENDSCAN GOTO m.lnOldRec &&Restore current record for scan loop in calling function ENDFUNCAnd of course some customized function is needed to add root level elements:
FUNCTION AddRootElements SCAN FOR crelative = '0' o.add(,1,alltrim(ckey),alltrim(ctext),0) AddChildren(alltrim(ckey)) ENDSCAN ENDFUNC>Why do I get an error OLE IDispatch exception code 0 from Nodes: Element not found?
>sele treeview >set multilocks on >=cursorsetprop("buffering",5,"treeview") > >sele treeview >=tableupdate(.t.) >go top >o = thisform.oletreeview.nodes >o.clear > >scan > if alltrim(crelative) = '0' > o.add(,1,alltrim(ckey),alltrim(ctext),0) > else >erro >>> o.add(alltrim(crelative),4,alltrim(ckey), alltrim(ctext),0) > endif >endscan > >thisform.oletreeview.selecteditem = thisform.oletreeview.nodes(1) > >thisform.updateproperties(thisform.oletreeview.selecteditem) > >if loexpand=0 > loexpand=1 >else > thisform.cmdexpandcollapse.click >endif >>