Solved

Find function in CTreeCtrl

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now