Reputation: 1444
I show items in a TTreeView
object. When an Item has children the control paints a >
next to the icon (or a down pointing arrow if expanded).
I was wondering if I can tell the Item somehow to paint the >
even if no children have been added (yet).
There are certain conditions in my software where it makes sense to show the user there are children, without actually adding the children yet (That is then done when the item is selected)
Using c++ Builder 2009 VCL but this Q should be valid for Delphi as well.
Upvotes: 3
Views: 370
Reputation: 596256
In VCL, TTreeNode
has a HasChildren
property:
Indicates whether a node has any children.
HasChildren
is true if the node has subnodes, or false if the node has no subnodes. IfShowButtons
of the tree view is true, andHasChildren
is true, a plus (+) button will appear to the left of the node when it is collapsed, and a minus (-) button will appear when the node is expanded.Note: If a node has no children, setting
HasChildren
to true will show a (+) plus button, but will not add any child nodes and the node cannot be expanded.
So, you can set a node's HasChildren
to true before actual child nodes have been created for it. Then later on, once you have determined whether the node has any actual child nodes, you can reset HasChildren
to false if there are no child nodes present.
Despite what the documentation suggests above, attempting to expand a node that has no child nodes but does have HasChildren
set to true WILL trigger the TTreeView.OnExpanding
event, at least. That is a good place to populate the actual child nodes and update HasChildren
.
Upvotes: 12