Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tree View Control Problem 1

Status
Not open for further replies.

Creeder

Programmer
Jul 5, 2000
110
MY
Hi,

Is there a way that i can return the type of node (eg, parent or child node)i am currently selected in a TreeView Control?

Or do i need to write a function for that?

Thanks in advance.

Yue Jeen

[sig][/sig]
 
Hi,

So for the only way that I can think of when adding the node assign the value of the Tag property.

Thefore if i am adding a Child node , Tag = 'CHILD' and if Parent Node, Tag = 'PARENT', then i can determine the the type of node.

Is there another more efficient way of doing this?

Thanks again.

Yue Jeen


[sig][/sig]
 
I use node keys for that. Say, you have root nodes. Thay will have keys 'R1*'. Than subnodes will have key 'RN1*'. And so on. So, when I see that node have key 'R1N1F1T2Q3*', I always know that it is in first item of root, first subnode, first subnode, second subnode, third node. [sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
I haven't messed with the TreeView control in quite a while, but I seem to recall that you can get a reference to the Node objects using properties such as Parent and Child. These don't show up in the design-time VFP property sheet, so you might try running the form and looking at the properties within the debugger. [sig]<p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br> [/sig]
 
Robert, working with nodes for MS Tree View control is quite a big mess and when you use object references to Tree View nodes you often have C00000005 crash. In addition, some combination of calls to Tree View methods using nodes() collection causes such crash too. Need a lot of experimenting and testing before your application will be clear. I did made this 2 year ago and remember well how much of time we spent to investigate and fix all such problems.
I will very appreciate when someone will give me tree view control that is more useful for applications and do not cause VFP to crash. I tried CTI Technologies grid-like tree view control, but it is either too slow (cmpare to VFP grid) or too complex to program (compare to MS Tree View control). [sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
Hi Vlad and Robert,

The main reason why I need to know the node type is because when in NodeClick() event is fired, I will do something like

NodeClick()


SELECT company
*-- The parent key basically stores the company_id

LOCATE FOR company_id = node.parent.key && refer to parent key
<Refresh form to display values)

This is ok if i click on child node, however when i click on the parent node, obviously there will be an error.

Thefore if i can detect the node type i can do something like

SELECT company
*-- The parent key basically stores the company_id
DO CASE
CASE nodetype = 'CHILD'
LOCATE FOR company_id = node.parent.key
CASE nodetype = 'PARENT'
LOCATE FOR company_id = node.key
ENDCASE
<Refresh form to display values)

Any ideas? So far i am still using the TAG properties to determine whether it is a child or parent.

Thanks again.

Yue Jeen










[sig][/sig]
 
Following is sample code of node click routine from my 2-year old application. As you may see from sample, I store ID of record in key that looks like 'RRNNNN', where RR is root ID, NNNN is record ID.
In your sample you may store by the same way. Just key for root nodes will be 'RRNNNN', for childs - 'CCNNNN', but NNNN - the same ID for all nodes and subnodes. Its more simple, I guess...

Code:
*** ActiveX Control Event ***
LPARAMETERS node
if this.enabled
	with this.parent
		* select working alias and position record pointer to selected service (emulation of how grid control works)
		if not empty(.ServiceViewAlias) 
			if used(.ServiceViewAlias)
				select (.ServiceViewAlias)
                                * check for title line
				if val(substr(node.key,2))>0
					locate for serv_id = (val(substr(node.key,2)))
				else
                                        * here we have title - make eof in table
					if not eof()
						go bottom
						if not eof()
							skip
						endif
					endif
				endif
			endif
		endif
	endwith
endif
dodefault(node)
[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
Hi Creeder!
I think it is good idea to use the ISNULL() function.

ISNULL(NODE.PARENT) returns .T. if U have selected a parent node, because top level of nodes have not parents so property &quot;parent&quot; references to .NULL.

ISNULL(NODE.PARENT) returns .F. if U have selected a child
node, because it has a parent.

Marat Tolgambaev
tolgambaev@hotmail.com [sig][/sig]
 
Hi all,

I think i have the answers now. Once again thank you very much !

Yue Jeen [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top