windowsforms-devexpress-dot-xtratreelist-dot-treelist-35459711.md
Fires before a node is collapsed.
Namespace : DevExpress.XtraTreeList
Assembly : DevExpress.XtraTreeList.v25.2.dll
NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList
public event BeforeCollapseEventHandler BeforeCollapse
Public Event BeforeCollapse As BeforeCollapseEventHandler
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. |
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:
If you want specific actions to be performed each time a node is collapsed, consider using the TreeList.AfterCollapse event.
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;
}
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