Finding an item in TreeCtrl (recursive function)
Posted
by Yura Khodak
on October 2nd, 1998
HTREEITEM CTreeCtrlX::FindData(HTREEITEM hti, DWORD dwData) { if(hti == NULL) return NULL; if(GetItemData( hti ) == dwData) { Select( hti, TVGN_CARET); EnsureVisible( hti ); return hti; } hti = GetChildItem( hti ); do { HTREEITEM hti_res; if((hti_res = FindData( hti, dwData)) !=NULL ) return hti_res; }while( (hti = GetNextSiblingItem( hti )) != NULL ); return NULL; }
Comments
great ..!!!!!!!!!!!!!!!!
Posted by Legacy on 08/08/2003 12:00amOriginally posted by: Unmesh
thanx for code ..
ReplyYet Another FindItem, Avoiding Return Value Concerns
Posted by Legacy on 03/28/2003 12:00amOriginally posted by: just passing thru
Thank U very much
Posted by Legacy on 12/02/2002 12:00amOriginally posted by: Bijawara N Krishnaswamy
Thank u for the code.
I too tried the similar way but got struck in recursive calls.It really helped me a lot
-krishna
TreeView item Level
Posted by Legacy on 07/24/2002 12:00amOriginally posted by: Umakanth
In a Microsoft Tree View Control , how can we find a Item level i.e in terms of for ROOT it is 0,next item 1 like this.
If i select a one item in a treeview control, i want to know that level at which it as selected ?
How can i find out this, any help ?
Thank you.
-Umakanth
ReplyFaster way to do search
Posted by Legacy on 11/13/2000 12:00amOriginally posted by: Matt Honkanen
If you have a lot of entries in your tree then you might want to consider using a seperate CMap object to help when it comes time to do searching within the tree. This will yield extremely fast search speeds at the small expense of some additional overhead in the form of a map.
ReplyThis algorithm only half works.
Posted by Legacy on 07/31/2000 12:00amOriginally posted by: lauraf
This method does only half of what was asked for. If all you need is to perform an operation on the sought-for HTREEITEM, you're fine. The part of the method that calls Select and EnsureVisible works.
However, do not rely on the HTREEITEM returned by this method. It is not the right one. The right one gets overwritten as the recursion unwinds -- a common problem in recursive algorithms.
The method in Ridwan's comment returns the correct HTREEITEM.
ReplyHow about this ...
Posted by Legacy on 04/24/2000 12:00amOriginally posted by: Ridwan