This topic has not yet been rated - Rate this topic

TVM_EXPAND message

Applies to: desktop apps only

The TVM_EXPAND message expands or collapses the list of child items associated with the specified parent item, if any. You can send this message explicitly or by using the TreeView_Expand macro.

Parameters

wParam

Action flag. This parameter can be one or more of the following values:

ValueMeaning
TVE_COLLAPSE

Collapses the list.

TVE_COLLAPSERESET

Collapses the list and removes the child items. The TVIS_EXPANDEDONCE state flag is reset. This flag must be used with the TVE_COLLAPSE flag.

TVE_EXPAND

Expands the list.

TVE_EXPANDPARTIAL

Version 4.70. Partially expands the list. In this state the child items are visible and the parent item's plus sign (+), indicating that it can be expanded, is displayed. This flag must be used in combination with the TVE_EXPAND flag.

TVE_TOGGLE

Collapses the list if it is expanded or expands it if it is collapsed.

 

lParam

Handle to the parent item to expand or collapse.

Return value

Returns nonzero if the operation was successful, or zero otherwise.

Remarks

Expanding a node that is already expanded is considered a successful operation and SendMessage returns a nonzero value. Collapsing a node returns zero if the node is already collapsed; otherwise it returns nonzero. Attempting to expand or collapse a node that has no children is considered a failure and SendMessage returns zero.

When an item is first expanded by a TVM_EXPAND message, the action generates TVN_ITEMEXPANDING and TVN_ITEMEXPANDED notification codes and the item's TVIS_EXPANDEDONCE state flag is set. As long as this state flag remains set, subsequent TVM_EXPAND messages do not generate TVN_ITEMEXPANDING or TVN_ITEMEXPANDED notifications. To reset the TVIS_EXPANDEDONCE state flag, you must send a TVM_EXPAND message with the TVE_COLLAPSE and TVE_COLLAPSERESET flags set. Attempting to explicitly set TVIS_EXPANDEDONCE will result in unpredictable behavior.

The expand operation may fail if the owner of the treeview control denies the operation in response to a TVN_ITEMEXPANDING notification.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Commctrl.h

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
VB6 Declaration
Private Const TV_FIRST As Long = &H1100
Private Const TVM_EXPAND As Long = (TV_FIRST + 2)
Clarification of TVIS_EXPANDEDONCE
Some clarification of the TVIS_EXPANDEDONCE flag:
  • The first time an item is expanded, during processing of TVN_ITEMEXPANDING, you will see the TVIS_EXPANDED flag set, while the TVIS_EXPANDEDONCE flag is clear.
  • Every time after that, you will see both TVIS_EXPANDED and TVIS_EXPANDEDONCE flags set.
  • The only proper way to clear the TVIS_EXPANDEDONCE flag is to pass the TVE_COLLAPSE and TVE_COLLAPSERESET flags to TVM_EXPAND. Additionally, TVE_COLLAPSERESET will also remove all child items.
You can think of TVIS_EXPANDEDONCE as the "has been expanded at least once already" flag. This flag is useful in situations where you want to dynamically add children to a tree item, but only right at the point of expansion. The article http://support.microsoft.com/kb/131278 has a decent example of dynamically adding children but does not make use of the TVIS_EXPANDEDONCE flag and destroys all children each time the tree is collapsed. This is inconvenient if you want the tree to remember child expansion states.

One possible method is:
  • On, TVN_ITEMEXPANDING, if action is TVE_EXPAND and state flag TVIS_EXPANDEDONCE is clear, dynamically add children.
  • Do not add children on TVE_EXPAND when state flag TVIS_EXPANDEDONCE is set.
  • Do nothing when item is collapsed; specifically, do not remove children with TVE_COLLAPSERESET.