MFC CTreectrl - find item by data

abc abc 351 Reputation points
2020-11-30T08:45:05.5+00:00

Hi,

In MFC CTreeCtrl, I inserted items and set item data using SetItemData().

Now I want to search CTreeCtrl items by data which I set using SetItemData().How to do it?

Thanks.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,730 questions
0 comments No comments
{count} votes

Accepted answer
  1. David Lowndes 4,716 Reputation points
    2020-11-30T09:12:48.137+00:00

    I think you have to recurse through the control items from your root point, get the item data and do the comparison - similar to how this does.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Sheng Jiang 蒋晟 206 Reputation points
    2020-11-30T14:23:01.953+00:00

    you can create index on your data source that you want search with. then create a searchable data structure between HTREEITEM and your index value and look up by value later.

    e.g. if you want to do exact search based on an int field in your data source, when you add tree items and got HTREEITEM, add a new pair of <int, HTREEITEM> to a std::hashmap<int, HTREEITEM> object, then you can look up HTREEITEM by the int field value. if you want to do a greater then search based on the field, you can consider a self balancing BST. If you have multiple field to index, consider Boost's Multi-index containers.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.