Solved

Find function in CTreeCtrl

Posted on 2003-11-11
2
517 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
has22 challenge 11 93
scoreUp challenge 14 62
Message not shown 5 50
Increment column based of a FK 8 21
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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