May 02, 2024, 09:39:47 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Searching a treeview

Started by LarryMc, August 02, 2009, 10:23:10 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library