PowerBuilderThe Treeview control allows us to organize and display data hierarchically in a treeProgramThe performance is more flexible and user operations are more convenient. In general, the Treeview control allows you to easily search for and locate the required information by expanding and folding the branches. However, if there are many content layers in the control, when users do not know much about their content, enabling users to expand the branches one by one will reduce the efficiency. In this case, an automatic query method is required, let the user enter the information to be searched, and the program will find and locate the information in the Treeview control.
PowerBuilderThe Treeview control does not directly provide functions or methods to complete this function. That is to say, you cannot directly search for the required data in each node of the Treeview control. This control has a finditem () function that can be used to search for node items. However, this function cannot directly search for the data we are looking for, such as character text or numeric data,It can only be searched based on the handle of a node item of the Treeview control.. However, we can use this function to obtain the node item handle and further obtain the node item details. The finditem () function syntax is as follows:
Treeviewname. finditem (navigationcode, itemhandle)
treeviewname is the name of the Treeview control to be searched;
the navigationcode parameter is a treenavigation enumerated data type used to indicate the relationship between the itemhandle parameter and the node item to be searched. Valid values:
roottreeitem!
Search for the first item in the first layer.
nexttreeitem!
Find the next item after itemhandle in the same level;
previoustreeitem!
Find the item before itemhandle in the same level.
parenttreeitem!
Find the parent node of itemhandle.
childtreeitem!
find the first subnode of itemhandle.
firstvisibletreeitem!
Search for the first item visible in the Treeview control regardless of its level.
nextvisibletreeitem!
find the first item that has been expanded after itemhandle, which is not hierarchical.
previusvisibletreeitem!
find the first item that has been expanded before itemhandle, which is not hierarchical.
currenttreeitem! Obtain the current option.
drophighlighttreeitem!
Search for the items that have recently been set for the drophighlighted attribute.
the itemhandle parameter indicates the handle of the node item.
This function returns a long integer value. If the execution is successful, the processed node is returned. If the execution fails,-1 is returned. Except childtreeitem !, Finditem does not search for unexpanded items. The finditem can only be used to obtain the handle of a node item. To obtain the details of a node, you must also use the getitem () function of the Treeview control. This function obtains the status information of a node item through the node item handle, such as label, picture index, and childen. Only the status information such as the label value can be compared, we can determine whether the required node items have been found. This function is as follows:
Treeviewname. getitem (itemhandle, item)
Here, treeviewname is the name of the Treeview control; itemhandle is the handle of the node item to obtain information; item is a treeviewitem system object variable, used to store the information of node items.
Setpointer (hourglass !)
Long ll_handle
Long ll_handletree []
Long ll_level
Int li_find
Treeviewitem ltvi_1
Li_find = 0
TV _treeview.setredraw (false)
Ll_handle = TV _treeview.finditem (roottreeitem! , 0)
// TV _treeview.expandall (ll_handle) TV _treeview.expanditem (ll_handle)
Do While ll_handle> 0 TV _treeview.getitem (ll_handle, ltvi_1)
If ltvi_1.label = sle_content.text then
Li_find = 1
Exit
End if
Ll_handle = TV _treeview.finditem (nextvisibletreeitem! , Ll_handle) // TV _treeview.expandall (ll_handle) TV _treeview.expanditem (ll_handle)
Loop
Ll_level = 1
If ll_handle> 0 then
Ll_handletree [ll_level] = ll_handle
Ll_handle = TV _treeview.finditem (parenttreeitem! , Ll_handle)
Do While ll_handle> 0
Ll_level ++
Ll_handletree [ll_level] = ll_handle
Ll_handle = TV _treeview.finditem (parenttreeitem! , Ll_handle)
Loop end if
Ll_handle = TV _treeview.finditem (roottreeitem! , 0)
Do While ll_handle> 0
TV _treeview.collapseitem (ll_handle)
Ll_handle = TV _treeview.finditem (nexttreeitem! , Ll_handle)
Loop
Do While ll_level> 0 and li_find = 1
TV _treeview.expanditem (ll_handletree [ll_level])
If ll_level = 1 then
TV _treeview.selectitem (ll_handletree [ll_level])
TV _treeview.setfocus ()
Exit
Else ll_level -- end if Loop
TV _treeview.setredraw (true)