Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find function in CTreeCtrl

Posted on 2003-11-11
2
Medium Priority
?
545 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 11

Accepted Solution

by:
KurtVon earned 500 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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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