Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Adding nodes to a treeview from a table
Message
From
10/01/2007 09:09:47
 
 
To
09/01/2007 16:26:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 6
Miscellaneous
Thread ID:
01183973
Message ID:
01184153
Views:
18
Update: Sorry, I initially missed the part about rebuiding the tree later from new information in a table (or updated records) and refreshing. (I typically do it the way Greg suggested in his message and added the code below to the button)

This is a simple and neat litte example that Cetin Basoz provided in the past:
*--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
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Previous
Reply
Map
View

Click here to load this message in the networking platform