Skip to main content

TreeViewNode.Expanded Property

Gets or sets whether the node is expanded.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v22.1.dll

NuGet Package: DevExpress.Web


public virtual bool Expanded { get; set; }

Property Value

Type Default Description
Boolean false

true if the node is expanded; false if the node is collapsed.


Use the Expanded property to expand or collapse a node.

TreeView - Expanding and Collapsing Nodes

Note that changing the Expanded property in code doesn’t invoke the ASPxTreeView.ExpandedChanging and the ASPxTreeView.ExpandedChanged events.

To expand/collapse all nodes, use the following methods:

Server method Client method Describtion
ASPxTreeView.ExpandAll ASPxClientTreeView.ExpandAll Expands all nodes
ASPxTreeView.CollapseAll ASPxClientTreeView.CollapseAll Collapses all nodes
ASPxTreeView.ExpandToDepth None Expands all nodes to the specified depth


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