/*
because PB's Treeview control does not provide the search item function, this Program is a supplement to this shortcoming.
call Syntax:
findtreeitem (TV _tree, findby, data)
call parameters:
TV _tree: Treeview, specify search in the TV _tree tree
findby: Boolean, specify the search method
false-label) search
true-search by additional data
data: Any, specify the content to be searched
return value: long type. If it is found, return the handle of the found item;
if it is not found, return 0;
if an error occurs, back to-1
*/
Long li_cnt, ll_hdl []
Treeviewitem lt_tvi
Li_cnt = 1
Ll_hdl [1] = TV _tree.finditem (roottreeitem !, 0)
Do While li_cnt> 0
If TV _tree.getitem (ll_hdl [li_cnt], lt_tvi) =-1 then return-1
If findby then
If lt_tvi.data = data then
Return ll_hdl [li_cnt]
End if
Else
If lt_tvi.label = string (data) then
Return ll_hdl [li_cnt]
End if
End if
If lt_tvi.children then
Li_cnt ++
Ll_hdl [li_cnt] = TV _tree.finditem (childtreeitem !, Ll_hdl [li_cnt-1])
Else
Ll_hdl [li_cnt] = TV _tree.finditem (nexttreeitem !, Ll_hdl [li_cnt])
End if
Do While ll_hdl [li_cnt] <= 0
Li_cnt --
If li_cnt = 0 Then exit
Ll_hdl [li_cnt] = TV _tree.finditem (nexttreeitem !, Ll_hdl [li_cnt])
Loop
Loop
Return 0