/*
由于PB的TreeView控件没有提供查找项的功能,因此本程序算是对此一缺憾的补缺。
调用语法:
findtreeitem(tv_tree, findby, data)
调用参数:
tv_tree: TreeView, 指明在tv_tree树中查找
findby: boolean, 指明查找方式
false - 按标签(Label)查找
true - 按附加数据(data)查找
data: any, 指明要查找的内容
返回值:long型。若找到,返回找到的项的Handle;
若没有找到,返回0;
若出错,返回-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