Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Locating a value in a treeview
Message
 
To
11/08/2004 10:40:15
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00932345
Message ID:
00932397
Views:
32
This message has been marked as the solution to the initial question of the thread.

* Assure highlight: oTreeview.HideSelection=.f.
* Fire the Node click event
oTreeview.NodeClick(oTreeview.Nodes(al3parnt.ckey))
* or (simply) select the node (and not fire node click)
oTreeview.Nodes(al3parnt.ckey).Selected=.t.


>I have a form that has a parent table and a child table. The parent table's records are in a treeview (with many levels of branches). The child records are in a grid.
>
>I allow the user to search for values in the child table and I can successfully find the values and select the correct record in the grid. However, the treeview does not refresh. In other words, I need to determine how to know which node to select and expand so the selected treeview node matches the parent record in the parent table.
>
>The treeview node key should match al3parnt.ckey...
>
>Here is the code I use to search through the child table and select the right record in the grid and below that is the nodeclick so you can see how my node keys are set up and the relationship between the node keys and the parent table:
>
>
>IF EMPTY(THISFORM.text2.VALUE)
>	RETURN
>ENDIF
>IF !USED('al3parnt') .OR. !USED('al3child')
>	RETURN
>ENDIF
>
>STORE 0 TO mrecno, crecno
>IF !EOF('al3parnt')
>	STORE RECNO('al3parnt') TO mrecno
>ELSE
>	GO TOP
>	STORE RECNO('al3parnt') TO mrecno
>ENDIF
>IF !EOF('al3child')
>	STORE RECNO('al3child') TO crecno
>ELSE
>	GO ToP
>	STORE RECNO('al3child') TO crecno
>ENDIF
>
>SELE al3child
>SET FILTER TO
>LOCATE FOR UPPER(ALLTRIM(THISFORM.text2.VALUE)) $ UPPER(al3child.VALUE)
>
>IF !EOF('al3child')
>	krecno = 0
>	STORE RECNO('al3child') TO krecno
>	tctempkey = al3child.cp_ID
>	SELE al3parnt
>	LOCATE FOR al3parnt.ckey = tctempkey
>	IF !FOUND('al3parnt')
>		GOTO mrecno
>		SELE al3child
>		GOTO crecno
>		SELE al3parnt
>	ELSE
>		ptkey = al3parnt.ckey
>		THISFORM.grdElements.RECORDSOURCE=''
>		SELE al3parnt
>		SET ORDER TO 0
>		SELE al3child
>		SET ORDER TO TAG cp_ID
>		SELE al3parnt
>		SET RELATION TO ckey INTO al3child
>		SELE al3child
>		SET FILTER TO UPPER(ALLTRIM(al3child.cp_ID)) = ALLTRIM(UPPER(al3parnt.ckey))
>		GO TOP
>		IF krecno > 0
>			GOTO krecno
>		ENDIF
>		THISFORM.grdElements.RECORDSOURCE='al3child'
>		THISFORM.grdElements.REFRESH()
>		thisform.grdElements.SETFOCUS()
>                *Here I need to select the correct node in the treeview
>	ENDIF
>ELSE
>	SELE al3child
>	GOTO crecno
>	SELE al3parnt
>	GOTO mrecno
>	SELE al3child
>	SET FILTER TO UPPER(ALLTRIM(al3child.cp_ID)) = ALLTRIM(UPPER(al3parnt.ckey))
>	GO TOP
>	THISFORM.grdElements.RECORDSOURCE='al3child'
>	THISFORM.grdElements.REFRESH()
>ENDIF
>
>NodeClick:
>
>*** ActiveX Control Event ***
>LPARAMETERS NODE
>
>* this loNode is being selected by the user
>
>NODE.ensurevisible
>
>IF USED('al3parnt') .AND. USED('al3child')
>	THISFORM.grdElements.RECORDSOURCE=''
>	SELE al3parnt
>	SET ORDER TO 0
>	SELE al3child
>	SET ORDER TO TAG CP_ID
>	SELE al3parnt
>	SET RELATION TO ckey INTO al3child
>	SELE al3child
>	SET FILTER TO al3child.CP_ID = al3parnt.ckey
>
>	SELECT al3parnt
>	GO TOP
>	DO CASE
>		CASE LEFT(ALLTRIM(UPPER(node.text)),11) = "TRANSACTION"			&& new transaction
>			lcSelf = LEFT(NODE.KEY,AT('_',NODE.KEY)-1)
>			lcSeq  = SUBSTR(NODE.KEY,AT('_',NODE.KEY)+1)
>			SELE al3parnt
>			SET ORDER TO TAG cSelf
>			GO TOP
>			LOCATE FOR cSelf = lcSelf AND Seq = lcSeq
>		OTHERWISE
>			SELE al3parnt
>			SET ORDER TO TAG ckey
>			GO TOP
>			LOCATE FOR ckey = node.key
>	ENDCASE
>
>	IF FOUND('al3parnt')
>		SELE al3child
>		SET FILTER TO UPPER(ALLTRIM(al3child.CP_ID)) = ALLTRIM(UPPER(al3parnt.ckey))
>		GO TOP
>		THISFORM.grdElements.RECORDSOURCE='al3child'
>	ENDIF
>	THISFORM.grdElements.REFRESH()
>ENDIF
>
>
>Here is the code I run that populates the treeview:
>
>
>
>#define tvwFirst    0 && The Node is placed before all other nodes at the same level of the node named in relative.
>#define tvwLast     1 && The Node is placed after all other nodes at the same level of the node named in relative. Any Node added subsequently may be placed after one added as Last.
>#define tvwNext     2 && (Default) The Node is placed after the node named in relative.
>#define tvwPrevious 3 && The Node is placed before the node named in relative.
>#define tvwChild    4 && The Node becomes a child node of the node named in relative.#DEFINE tvwFirst	0
>#DEFINE cnLOG_PIXELS_X     88
>#DEFINE cnLOG_PIXELS_Y     90
>#DEFINE cnTWIPS_PER_INCH 1440
>
>IF !USED('al3parnt')
>	WAIT WINDOW "An error occurred! Could not open al3parnt." NOWAIT
>	RETURN
>ENDIF
>IF !USED('al3child')
>	WAIT WINDOW "An error occurred! Could not open al3child." NOWAIT
>ENDIF
>PRIVATE onode, mstartkey, tnode
>mstartkey=''
>THIS.SHOW
>THIS.oletreeview.nodes.clear()
>WITH THIS.oletreeview.nodes
>	onode=.ADD(,tvwFirst,'File_Name'+'_'+'0000',thisform.Al3_file)
>	IF TYPE('onode')="O"
>		onode.expanded = .T.
>	ENDIF
>	onode=.ADD('File_Name'+'_'+'0000',tvwChild,'Message1'+'_'+'0000','Message(1)')
>	IF TYPE('onode')="O"
>		onode.expanded = .T.
>	ENDIF
>	SELE Al3Parnt
>	SET ORDER TO 0
>	SCAN
>		DO CASE
>		CASE Al3Parnt.cself = "1MHG"			&& message header
>			tnode=.ADD('Message1'+'_'+'0000',tvwChild,al3parnt.ckey,TRIM(al3Parnt.cSelf))
>			STORE al3parnt.ckey TO mstartkey
>		CASE Al3Parnt.cself = "2TRG"			&& new transaction
>			onode=.ADD('Message1'+'_'+'0000',tvwChild,'2TRG'+'_'+SEQ,'Transaction('+ALLTRIM(STR(al3Parnt.ntran))+')')
>		CASE Al3Parnt.cself = "3MTG"			&& message Trailer
>			.ADD('Message1'+'_'+'0000',tvwChild,al3parnt.ckey,LEFT(TRIM(al3Parnt.cSelf),4))
>		CASE Al3Parnt.cPARENT = "A0"          &&  this record's parent 'branch' A0 is always top level branch
>			onode=.ADD('2TRG'+'_'+SEQ,tvwChild,al3parnt.ckey,TRIM(Al3Parnt.label))
>		ENDCASE
>	ENDSCAN
>	IF TYPE('tnode')="O" .and. TYPE('mstartkey')="C" .and. !EMPTY(mstartkey)
>		THIS.oletreeview.nodes(mstartkey).Selected=.t.
>		THIS.oletreeview.nodeclick(tnode)
>	ENDIF
>ENDWITH
>RETURN
>
Imagination is more important than knowledge
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform