Search code examples
delphivcldelphi-2007

Can I make a TTreeNode invisible?


TTreeNode does not have a Visible property, so the obvious option does not exist. Is there any other way to make a TTreeNode and all its child nodes invisible? Of course I want to be able to make it visible again later.

This is with Delphi 2007.

Note#1: I am aware of the alternative TVirtualTreeView, and I will check it out if there is no easy way to accomplish this with TTreeView.

Note#2: I need the option only for top level nodes. The ones I want to hide usually don't even have children.


Solution

  • It's a good idea to separate data from the user interface, and this issue with tree views is a good example - don't store data in a tree view. I often have a non-visual unit that contains a structured class that stores data. A user interface unit can have a treeview that can displays (a configurable subset of) data from that class. There are a variety of ways to move data between the two. This type of isolation requires a bit of planning, but provides much greater flexibility and stability.