*--Courtesy Cetin Basoz, Universal Thread *--When prompted, insert the Microsoft TreeView Control SET SAFETY OFF CREATE TABLE tree (node N(2),child n(2), detail c(50)) INSERT INTO tree (node, child, detail) VALUES (1 ,0,"Root") INSERT INTO tree (node, child, detail) VALUES (2 ,1,"PAIDUP CAPITAL") INSERT INTO tree (node, child, detail) VALUES (3 ,2,"John Smith") INSERT INTO tree (node, child, detail) VALUES (4 ,2,"Terry Jones") INSERT INTO tree (node, child, detail) VALUES (5 ,1,"DIRECTORS ACCOUNTS") INSERT INTO tree (node, child, detail) VALUES (6 ,5,"Patti Marshall") INSERT INTO tree (node, child, detail) VALUES (7 ,5,"Kelly Simpson") INSERT INTO tree (node, child, detail) VALUES (8 ,1,"RESERVES") INSERT INTO tree (node, child, detail) VALUES (9 ,8,"Profit & Loss b/f") INSERT INTO tree (node, child, detail) VALUES (10,8,"Profit & Loss last year") INDEX ON STR(child,5)+STR(node,5) TAG tree oform = NEWOBJECT('treeviewtest') oform.show() llcontinue = .T. DO WHILE llcontinue read events ENDDO CLOSE ALL RETURN DEFINE CLASS treeviewtest AS form Top = 0 Left = 0 Height = 400 Width = 375 DoCreate = .T. Caption = "Form1" Name = "treeviewform" ADD OBJECT oletree AS olecontrol WITH ; Top = 12, ; Left = 12, ; Height = 336, ; Width = 336, ; Name = "oletree" ADD OBJECT command1 AS commandbutton WITH ; Top = 360, ; Left = 132, ; Height = 27, ; Width = 84, ; Caption = "Rebuild Tree", ; Name = "Command1" PROCEDURE rebuildtree thisform.LockScreen = .t. o = ThisForm.oleTree o.nodes.clear SELECT tree GO TOP SCAN IF tree.child = 0 oNode = o.nodes.add(,1,ALLTRIM(STR(tree.node))+"_",ALLTRIM(tree.detail),,) oNode.ForeColor = RGB(128,0,128) thisform.oleTree.SelectedItem = oNode ELSE oNode = o.nodes.add(ALLTRIM(STR(tree.child))+"_",4,ALLTRIM(STR(tree.node))+"_", ALLTRIM(tree.detail),,) ENDIF IF tree.child # 0 oNode.ForeColor = RGB(0,0,255) ENDIF oNode.Expanded = .t. ENDSCAN thisform.LockScreen = .f. ENDPROC PROCEDURE Init this.rebuildtree() return .t. ENDPROC PROCEDURE command1.Click SELECT tree LOCATE FOR 'new records' $ LOWER(detail) IF !FOUND() INSERT INTO tree (node, child, detail) VALUES (11,1,"New Records") INSERT INTO tree (node, child, detail) VALUES (12,11,"Sandy Taylor") INSERT INTO tree (node, child, detail) VALUES (13,11,"Jeffrey Thompson") ENDIF thisform.rebuildtree() thisform.refresh() ENDPROC PROCEDURE Destroy llcontinue = .F. CLEAR EVENTS DODEFAULT() ENDPROC ENDDEFINE