Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Moving A TreeView Node
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Divers
Thread ID:
01036288
Message ID:
01036377
Vues:
32
Kevin,

** Update
** I replaced the previous recursive code that was not working as I thought **
**

The following code is not completely tested, just threw it up fast, so fast that you will need to select the treeview control from the list in order to make it work, but I think it would give you an idea to solve this (note that I am not checking much things, so be sure to select one of the Childs or GrandChilds in your test, just in case, also, I would have set escape on, in case the I screwed with the recursion :) )
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN


	**************************************************
*-- Form:         form1 (c:\testtree.scx)
*-- ParentClass:  form
*-- BaseClass:    form
*-- Time Stamp:   07/27/05 11:37:02 AM
*
DEFINE CLASS form1 AS form


	Top = 0
	Left = 0
	Height = 448
	Width = 382
	DoCreate = .T.
	Caption = "Form1"
	*-- XML Metadata for customizable properties
	_memberdata = ""
	Name = "Form1"


	ADD OBJECT oletree AS olecontrol WITH ;
		Top = 24, ;
		Left = 20, ;
		Height = 341, ;
		Width = 335, ;
		Name = "oleTree"


	ADD OBJECT command1 AS commandbutton WITH ;
		Top = 394, ;
		Left = 23, ;
		Height = 27, ;
		Width = 181, ;
		Caption = "Move Selected Node Up", ;
		Name = "Command1"


	ADD OBJECT text1 AS textbox WITH ;
		Height = 23, ;
		Left = 220, ;
		ReadOnly = .T., ;
		Top = 396, ;
		Width = 137, ;
		Name = "Text1"


	PROCEDURE oletree.NodeClick
		*** ActiveX Control Event ***
		LPARAMETERS node

		thisform.command1.Refresh()
		thisform.Text1.Refresh()
	ENDPROC


	PROCEDURE oletree.Init
		local loNode

		with this.Nodes
			.Add(,, 'Root', 'Root Node')
			.Add('Root', 4, 'Child1', 'First Child')
			.Add('Root', 4, 'Child2', 'Second Child')
			.Add('Root', 4, 'Child3', 'Third Child')
			.Add('Child1', 4, 'GrandChild1', 'First GrandChild')
			.Add('Child1', 4, 'GrandChild2', 'Second GrandChild')
			.Add('Child2', 4, 'GrandChild3', 'Third GrandChild')
			.Add('Child2', 4, 'GrandChild4', 'Fourth GrandChild')
			.Add('Child3', 4, 'GrandChild5', 'Fifth GrandChild')
			.Add('Child3', 4, 'GrandChild6', 'Sixth GrandChild')
			.Add('Child3', 4, 'GrandChild7', 'Seventh GrandChild')
			.Add('Child3', 4, 'GrandChild8', 'Eigth GrandChild')
			.Add('Child3', 4, 'GrandChild9', 'Nineth GrandChild')
			.Add('Child3', 4, 'GrandChild10', 'Tenth GrandChild')
			.Add('Child3', 4, 'GrandChild11', 'Eleventh GrandChild')
			.Add('Child3', 4, 'GrandChild12', 'Twelveth GrandChild')
		endwith

		for each loNode in this.Nodes
			loNode.Expanded		= .t.
		endfor
	ENDPROC


	PROCEDURE command1.Click
		local loNodeToMove, loNextNode, loPrevious, loNodes, loParent, loNode

		loNodeToMove		= thisform.oleTree.SelectedItem
		loPrevious			= loNodeToMove.Previous
		loParent			= loNodeToMove.Parent

		if not Isnull(loPrevious)
			loNodes				= Createobject('Collection')

			do while not Isnull(loPrevious.Previous)
				with loNodes as Collection
					.Add(loPrevious.Previous)
					loPrevious	= loPrevious.Previous
				endwith
			enddo

			loNodeToMove.Parent	= loParent
			for each loNode in loNodes
				loNode.Parent		= loParent
			endfor
		endif
	ENDPROC


	PROCEDURE command1.Refresh
		this.enabled	= not Isnull(thisform.oleTree.SelectedItem) and thisform.oleTree.SelectedItem.Key # 'Root'
	ENDPROC


	PROCEDURE text1.Refresh
		this.Value	= Iif(Isnull(thisform.oleTree.SelectedItem), .null., thisform.oleTree.SelectedItem.Key + ' (' + Transform(thisform.oleTree.SelectedItem.Index) + ')')
	ENDPROC


ENDDEFINE
*
*-- EndDefine: form1
**************************************************
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform