>CREATE TABLE tree (node N(2),child n(2), detail c(50)) >INSERT INTO tree (node, child, detail) VALUES (1,0,"PAIDUP CAPITAL") >INSERT INTO tree (node, child, detail) VALUES (1,1,"Eric den Doop") >INSERT INTO tree (node, child, detail) VALUES (1,2,"Cetin Basoz") >INSERT INTO tree (node, child, detail) VALUES (2,0,"DIRECTORS ACCOUNTS") >INSERT INTO tree (node, child, detail) VALUES (2,1,"Sergy") >INSERT INTO tree (node, child, detail) VALUES (2,2,"Borislav Borissov") >INSERT INTO tree (node, child, detail) VALUES (3,0,"RESERVES") >INSERT INTO tree (node, child, detail) VALUES (3,1,"Profit & Loss b/f") >INSERT INTO tree (node, child, detail) VALUES (3,2,"Profit & Loss last year") >>
Create cursor tree (Node N(2),Child N(2), detail c(50)) Insert Into tree (Node, Child, detail) Values (1,0,"PAIDUP CAPITAL") Insert Into tree (Node, Child, detail) Values (1,1,"Eric den Doop") Insert Into tree (Node, Child, detail) Values (1,2,"Cetin Basoz") Insert Into tree (Node, Child, detail) Values (2,0,"DIRECTORS ACCOUNTS") Insert Into tree (Node, Child, detail) Values (2,1,"Sergy") Insert Into tree (Node, Child, detail) Values (2,2,"Borislav Borissov") Insert Into tree (Node, Child, detail) Values (3,0,"RESERVES") Insert Into tree (Node, Child, detail) Values (3,1,"Profit & Loss b/f") Insert Into tree (Node, Child, detail) Values (3,2,"Profit & Loss last year") * Convert to a UniqueNodeId, ParentId, NodeText style Select ; '_'+Padl(Node,5,'0')+Padl(Child,5,'0') As NodeId,; Iif(Child=0,space(11),'_'+Padl(Node,5,'0')+Padl(0,5,'0')) As ParentId,; detail As NodeText ; from tree ; order By 1 ; into Cursor myTree #Define tvwFirst 0 #Define tvwLast 1 #Define tvwNext 2 #Define tvwPrevious 3 #Define tvwChild 4 Public oForm oForm = Createobject('myForm') oForm.Show Define Class myForm As Form Height = 300 Width = 500 DoCreate = .T. Caption = "TreeView - testpad" Add Object myTree As OleControl With ; Height = 300, ; Width = 500, ; OleClass = 'MSComCtlLib.TreeCtrl' *-- Fill the tree values Procedure filltree Lparameters tcAlias This.Show Select (m.tcAlias) With This.myTree.Nodes Scan If Empty(ParentID) .Add(,tvwFirst,NodeId,Trim(NodeText)) Else .Add(ParentId,tvwChild,NodeId,Trim(NodeText)) Endif Endscan Endwith Endproc Procedure Init With This.myTree .linestyle =1 .labeledit =1 .indentation = 5 .PathSeparator = '\' .Scroll = .T. .OLEDragMode = 0 .OLEDropMode = 0 Endwith This.filltree('myTree') Endproc EnddefineA better structure is with unique keys per node, level and order fields to allow you later add new nodes in desired position. ie: With above code change part above "#Define tvwFirst" line:
Declare Integer UuidCreate In 'RPCRT4.dll' String @pguid Declare Integer StringFromGUID2 In 'Ole32.dll' ; string rguid, String @lpsz, Integer cchMax Local lcParentID Create Cursor tree (NodeID c(38), ParentID c(38), detail c(50),nLevel i,nOrder i) Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),'',"PAIDUP CAPITAL",0,10) * Add children of this node lcParentID = tree.NodeID Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),m.lcParentID,"Eric den Doop",1,10) Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),m.lcParentID,"Cetin Basoz",1,20) Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),'',"DIRECTORS ACCOUNTS",0,10) * Add children of this node lcParentID = tree.NodeID Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),m.lcParentID,"Sergy",1,10) Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),m.lcParentID,"Borislav Borissov",1,20) Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),'',"RESERVES",0,10) * Add children of this node lcParentID = tree.NodeID Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),m.lcParentID,"Profit & Loss b/f",1,10) Insert Into tree (NodeID,ParentID,detail,nLevel,nOrder) Values ; (GetGUID(),m.lcParentID,"Profit & Loss last year",1,20) Select NodeID,ParentID,detail As NodeText ; From tree ; Order By nLevel,nOrder ; Into Cursor myTreePS:
Function GetGUID Local pguid,rguid pguid=Replicate(Chr(0),16) rguid=Replicate(Chr(0),80) UuidCreate(@pguid) StringFromGUID2(pguid,@rguid,40) Return Strconv(Left(rguid,76),6)Cetin