Skip to main content

ASPxTreeView.ExpandedChanging Event

Fires before the expansion state of a node is changed by end-user interaction.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.2.dll

NuGet Package: DevExpress.Web


public event TreeViewNodeCancelEventHandler ExpandedChanging

Event Data

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

Property Description
Cancel Gets or sets a value indicating whether the action that raised the event should be canceled.
Node Gets a node object related to the event. Inherited from TreeViewNodeEventArgs.


Write an ExpandedChanging event handler to perform specific actions before each time a node’s expansion state is changed by end-user interaction. You can use the event parameter’s properties to identify the node being manipulated and cancel execution of the command, if necessary.


The sample code below represents an ASPxTreeView.ExpandedChanging event handler. The event handler prevents collapsing nodes if it has selected children in any generation.

View Example

<dx:ASPxTreeView ID="ASPxTreeView1" runat="server" DataSourceID="XmlDataSource1" AutoPostBack="True" AllowSelectNode="True" OnExpandedChanging="ASPxTreeView1_ExpandedChanging">
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/MenuTabbedMenu.xml"
using DevExpress.Web.ASPxTreeView;

public partial class _Default : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e) {

    protected void ASPxTreeView1_ExpandedChanging(object source, DevExpress.Web.ASPxTreeView.TreeViewNodeCancelEventArgs e) {
        if ((e.Node.Expanded) && (ASPxTreeView1.SelectedNode != null)) {
            TreeViewNode  node = ASPxTreeView1.SelectedNode.Parent;
            while (node != null) {
                if (e.Node == node) {
                    e.Cancel = true;
                node = node.Parent;
See Also