Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 21: Tree and List Controls Visual C++ and MFC Fundamentals


When a node has children or leaves, to show this, you
may want to display lines connecting these
relationships. To do this at design time, set the Has
Lines proeprty to True:

If you are programmatically creating the control and
you want to display lines among related nodes, add
the TVS_HASLINES style.

A node that has dependent children can display or
hides them. To display its leaves, a node must be
expanded. To hide its leaves, a node must collapse.
These operations must be obvious to the user but
something should indicate whether a node has
dependent or not. This can be illustrated by a button
that accompany such a node. To add these buttons to
the control, at design time, set the Has Buttons
property to True. This is equivalent to dynamically
creating a tree list with the TVS_HASBUTTONS
style:

Unless you have a reason to do otherwise, it is usually
a good idea to combine both the Has Buttons (or
TVS_HASBUTTONS) and the Has Lines (or
TVS_HASLINES) styles:

To show which item is the root, or which items play the roles of roots, of the tree list, you
can display a line from the root(s) to the child(ren). To do this, at design time, set the
Lines At Root property to True or add the TVS_LINESATROOT style. The line from
the root(s) to to the child(ren) can display only if the control has the Has Lines property
set to True or the TVS_HASLINES style.

When using the list, the user typically selects an item
by clicking it. If you want the mouse cursor to turn into
a pointer finger and to underline the item when the
mouse is over the node, set the Track Select property
to True or create the control with the
TVS_TRACKSELECT style.

Once the mouse pointer is on top of the desired item,
the user can click to select it.

When the user clicks another control or another application, the node that was selected
would lose its selection as the tree control would have lost focus. If you want the tree to
always show the selected item even if the control loses focus, set its Show Selection
Free download pdf