Skip to main content
A newer version of this page is available. .

TreeList.BeforeCollapse Event

Fires before a node is collapsed.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v20.1.dll

NuGet Package: DevExpress.Win.TreeList

Declaration

public event BeforeCollapseEventHandler BeforeCollapse

Event Data

The BeforeCollapse event's data class is BeforeCollapseEventArgs. The following properties provide information specific to this event:

Property Description
CanCollapse Gets or sets a value indicating whether a Tree List node can collapse.
Node Gets the current Tree List node. Inherited from NodeEventArgs.

Remarks

By default, the following actions result in collapsing a parent node:

Each time a node is about to be collapsed, the BeforeCollapse event fires. Write a handler for this event to specify whether the node is allowed to be collapsed. You must set the event’s BeforeCollapseEventArgs.CanCollapse parameter to false to prohibit this action.

You can use the event for the following purposes:

  • Prohibit the ability to collapse a specific node(s).
  • Allow the ability to collapse nodes only when certain conditions are met.

If you want specific actions to be performed each time a node is collapsed, consider using the TreeList.AfterCollapse event.

Example

The following sample code prohibits collapsing root-level nodes. The TreeList.BeforeCollapse event is handled for this purpose.

using DevExpress.XtraTreeList;

private void treeList1_BeforeCollapse(object sender, BeforeCollapseEventArgs e) {
   if (e.Node.Level == 0) e.CanCollapse = false;
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the BeforeCollapse event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also