Skip to main content

TreeList.BeforeCollapse Event

Fires before a node is collapsed.

Namespace: DevExpress.XtraTreeList

Assembly: DevExpress.XtraTreeList.v24.1.dll

NuGet Packages: DevExpress.Win.Navigation, 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;
}
See Also