Solved

Find function in CTreeCtrl

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference between String.subString() and String.subSequence() 6 294
either24  challenge 19 110
FizzBuzz challenge 9 87
Change to event 1 138
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…
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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