BeforeCollapse Event

TreeView.BeforeCollapse Event

 

Occurs before the tree node is collapsed.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member BeforeCollapse : IEvent<TreeViewCancelEventHandler,
    TreeViewCancelEventArgs>

For more information about how to handle events, see Handling and Raising Events.

The following code example demonstrates how to change the collapse state of a TreeView so that all the checked nodes are visible. First, all the nodes are expanded, and a handler is added for the BeforeCollapse event. Next, all the nodes are collapsed. The BeforeCollapse event handler determines whether a given node has child nodes that are checked. If a node has checked children, the collapse is canceled for that node. In order to allow standard node collapse when the minus sign next to a node is clicked, the BeforeCollapse event handler is then removed.

This behavior can also be implemented by handling the BeforeExpand event, as illustrated in the example for that topic.

For the complete example, see the TreeView constructor reference topic.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft