Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting child nodes of a treeview
Message
From
01/12/2006 03:29:42
 
 
To
30/11/2006 19:13:03
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Environment versions
Visual FoxPro:
VFP 6
Miscellaneous
Thread ID:
01173946
Message ID:
01174023
Views:
15
>Now that I'm able to get the child nodes of a parent node or selected node, I'd like now to get the child nodes of these child nodes and append it to a table.
>
>My current code is this
>
>nodeptr = thisform.oletreeview.selecteditem
>
>local childnodeptr
>childnodeptr = m.nodeptr.child
>
>select ckey from treeview into cursor csrtemp where alltrim(ckey)==nodeptr.key
>use (dbf([csrtemp])) again in 0 alias csrtable
>select csrtable
>use in csrtemp
>
>do while !isnull(m.childnodeptr)
>	append blank
>	replace ckey with m.childnodeptr.key
>	childnodeptr = m.childnodeptr.next
>enddo
>
>
>
>I want my table to look like this,
>
>Selected node
> Child 1 of selected node
> Child 1.1
> Child 1.2
> Child 1.2.1
> Child 1.2.2
> Child 1.3
> Child 2 of selected node
> Child 2.1
> Child 2.1.1
> Child 3 of selected node
> Child 3.1
> Child 3.2
>
>Any one help me?

Evelyn,

I think you want the preorder traversal, ie
Process the node
Process each Child Node from left to right in preorder
Untested code below

There are two ways
(1) Recursive

(2) Iterative (with a stack)
&& recursive
NodePtr = thisform.oletreeview.selecteditem
=Cursor_Fill(NodePtr)


...

function Cursor_Fill(NodePtr) && Depth first
	
	local Success
	Success = TRUE
	
	local ChildNodePtr
	
	do case
	case isnull(m.NodePtr)
	
	otherwise
		append blank
		replace ckey with m.NodePtr.Key
		 
		ChildNodePtr = m.NodePtr.Child
		
		do while m.Success and !IsNull(m.ChildNodePtr)
			
			do case
			case !Cursor_Fill(m.ChildNodePtr)
				assert FALSE
				Success = FALSE
			
			otherwise
				ChildNodePtr = m.ChildNodePtr.next
			
			endcase
		enddo
	
	endcase
	
	return m.Success

endfunc
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform