2
votes

I am working on a project implemented using WIN32 APIs, where I need some of the tree-view items at run time to be visible/invisible, based on some data entered by user. I have done some work, where I found that I can add/delete item in a tree-view control but can't find anywhere how to set item visible or invisible(I found some examples where it can be done through MFC).

I am looking for the way to set them as visible/invisible is simply because when I add an item, it requires significant back-end calculations, that repeated addition or removal will result in performance issues. I only want to do that calculation only once per tree view item.

One of the solution, I have thought, if setting tree-view item is not possible, is to simply have a linked list of tree-view items present, and add/delete only those items that are required to be visible/invisible.

Please, tell me if it is possible to set tree-view item's state as visible/invisible, If yes, then how? And if no, what can be other alternate solutions?

1
Imho, there is not another way you mentioned (add/delete).Maximus
Keep a separate cache of the data displayed in treeview items. If you need to recreate an item that has previously been deleted you can cheaply retrieve the data from the cache. Depending on your data you might be able to use a simple std::map for the cache, or you might need some kind of tree.arx
Have you tried hooking the TVM_GETITEMRECT message to zero out the bounding rectangle on "hidden" items? Note that you'll need to hook other messages in order to prevent "hidden" items from being selected.Jay

1 Answers

5
votes

The standard TreeView control does not have any concept of node visibility. Adding/deleting nodes is the only option. You will have to maintain a separate linked list cache of data that the nodes display (which you should do anyway so you separate your UI logic from your business logic). Otherwise, you need to write your own TreeView control, or find a third-party implementation, that suites your needs.