Back to Devexpress

TreeList.BeforeCollapse Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-35459711.md

latest4.1 KB
Original Source

TreeList.BeforeCollapse Event

Fires before a node is collapsed.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
public event BeforeCollapseEventHandler BeforeCollapse
vb
Public Event BeforeCollapse As BeforeCollapseEventHandler

Event Data

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

PropertyDescription
CanCollapseGets or sets a value indicating whether a Tree List node can collapse.
NodeGets 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.

csharp
using DevExpress.XtraTreeList;

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

Private Sub TreeList1_BeforeCollapse(ByVal sender As Object, _
ByVal e As BeforeCollapseEventArgs) Handles TreeList1.BeforeCollapse
   If e.Node.Level = 0 Then e.CanCollapse = False
End Sub

See Also

BeforeExpand

AfterCollapse

Expanded

CollapseAll()

CollapseToLevel(Int32)

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace