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!

Find in treeview 1

Status
Not open for further replies.

ercsi1

Programmer
Mar 26, 2007
2
HU
Hi!
I would like write a function for find a data in the tree. But I getting gave up... I wrote this until now:

long idxroot, idxchild, idx, ret
treeviewitem tvi

idx = tv_1.finditem ( roottreeitem!, 0)
idxchild = tv_1.finditem ( childtreeitem!, idx )

do while idxchild <> -1
do while idx <> -1
ret = tv_1.getitem( idx , tvi )
if tvi.data = ID then return ret
idx = tv_1.finditem( nexttreeitem!, idx )
loop
idxchild = tv_1.finditem ( childtreeitem!, idxchild )
idx = idxchild
loop

return idx
 
oh, just a comment... I don't have PFC...
 
Just a comment... The root can have siblings... I believe you should be able to do the NextTreeItem! in the outer loop, and the ChildTreeItem! in the inner, and that should take care of the root's siblings.
 
you can try this :
Code:
//====================================================================
// Function: wf_findtvitem()
//--------------------------------------------------------------------
// Arguments:
// 	value	string	as_code	
//--------------------------------------------------------------------
// Return:  (none)
//--------------------------------------------------------------------

Long ll_find,ll_handle,ll_level,ll_handletree[]
treeviewitem ltvi_1
ll_find = 0
itv_active.Setredraw(False)
ll_handle = itv_active.Finditem(RootTreeItem! ,0)
itv_active.Expandall(ll_handle)
DO WHILE ll_handle > 0
	itv_active.Getitem(ll_handle,ltvi_1)
	IF ltvi_1.Data = as_code THEN
		ll_find = 1
		EXIT
	END IF
	ll_handle = itv_active.Finditem(NextVisibleTreeItem! ,ll_handle)
	itv_active.Expandall(ll_handle)
LOOP
ll_level = 1
IF ll_handle > 0 THEN
	ll_handletree[ll_level] = ll_handle
	ll_handle = itv_active.Finditem(ParentTreeItem! ,ll_handle)
	DO WHILE ll_handle > 0
		ll_level ++
		ll_handletree[ll_level] = ll_handle
		ll_handle = itv_active.Finditem(ParentTreeItem! ,ll_handle)
	LOOP
END IF
ll_handle = itv_active.Finditem(RootTreeItem! ,0)
DO WHILE ll_handle > 0
	itv_active.Collapseitem(ll_handle)
	ll_handle = itv_active.Finditem(NextTreeItem!  ,ll_handle)
LOOP

DO WHILE ll_level > 0 And ll_find = 1
	itv_active.Expanditem(ll_handletree[ll_level])
	IF ll_level = 1 THEN
		itv_active.Selectitem(ll_handletree[ll_level])
		itv_active.Setfocus()
		EXIT
	ELSE
		ll_level --
	END IF
LOOP
itv_active.Setredraw(True)

as this function is searching every item in the treeview,the efficiency is not so well.
but the treeview is offen linked to a datawindow,so you can find the treeview's branch through the datawindow as needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top