IonicWind Software

IWBasic => The Roundtable => Topic started by: LarryMc on August 02, 2009, 10:23:10 AM

Title: Searching a treeview
Post by: LarryMc on August 02, 2009, 10:23:10 AM
For a project I'm working on I needed to be able to find a specific node at the root level so that I could add a child node to it.
I created a little test routine.
The following code snippet will loop through all the root level nodes until it finds the matching text.

It would be easy enough to write nested loop searching to search children and children of children etc., if necessary.

global sub findtreeitem()
string s="games"
string a$=""
int found=0
'find the 1st root node
uint ih=SendMessage(win_index1,TVM_GETNEXTITEM,TVGN_ROOT,0 ,IDT_TREE1)
'get the node text
tvGetItemText(win_index1, IDT_TREE1, ih, a$, 255)
'see if it is a match, if so we are through
if lcase$(a$)= lcase$(s) then found=1
while found=0 & ih<>0
'see if the next sibling node is a match
ih=SendMessage(win_index1,TVM_GETNEXTITEM,TVGN_NEXT,ih ,IDT_TREE1)
tvGetItemText(win_index1, IDT_TREE1, ih, a$, 255)
print lcase$(ltrim$(rtrim$(a$)))," * ",lcase$(s),found
if lcase$(ltrim$(rtrim$(a$)))= lcase$(s) then found=1
endwhile
'select the item in the tree
tvSelectItem(win_index1, IDT_TREE1, ih)
print a$
return
endsub


Larry