Solved

Find function in CTreeCtrl

Posted on 2003-11-11
2
530 Views
Last Modified: 2013-11-20
Hi,
   There is tree control. Each node having some text.
    I want to check whether "abc" string exist in tree or not.
    You can say I just want to use find functionality.
    How can I do ?
0
Comment
Question by:NavinKaushik
  • 2
2 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 125 total points
ID: 9722567
The only way I know is to step through the tree and check each item.  Fortunately, it's easy to step through ignoring the tree structure (it's also easy to do it using the tree structure if you want to do something like find the most root-like item that matches):


HTREEITEM item = ctlTree->GetRootItem();
while ((item != NULL) && (ctlTree->GetItemText(item).CompareNoCase(strSearch) != 0))
{
    item = ctlTree->GetNextItem(item, TVGN_NEXTVISIBLE);
}
if (item != NULL)
    // Found the item.


Hope this helps.
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 9722802
Oh, and here's the method for searching if you want to check the non-visible items:


HTREEITEM GetMatchingItem(CString& strMatch, CTreeCtrl* ctlTree, HTREEITEM start /*= NULL*/)
{
    HTREEITEM item, child;

    if (start == NULL)
        item = ctlTree->GetRootItem();
    else
        item = start;

    while ((item != NULL) && (ctlTree->GetItemText(item).CompareNoCase(strMatch) != 0))
    {
        child = ctlTree->GetNextItem(item, TVGN_CHILD);
        child = GetMatchingItem(strMatch, ctlTree, child);
        if (child != NULL)
            return child;
        item = ctlTree->GetNextItem(item, TVGN_NEXT);
    }

    return item;
}


This was typed in on the fly, so watch out for bugs.

Hope this helps.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need to retreive data from .TFS file exported by DVR 8 244
bobThere java chalenge 45 95
maxBlock challenge 30 146
building a service to accessed via telnet client, want colors ? 4 97
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question