Back to Devexpress

TreeViewNode.Expanded Property

aspnet-devexpress-dot-web-dot-treeviewnode-645314c9.md

latest5.5 KB
Original Source

TreeViewNode.Expanded Property

Gets or sets whether the node is expanded.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
[DefaultValue(false)]
public virtual bool Expanded { get; set; }
vb
<DefaultValue(False)>
Public Overridable Property Expanded As Boolean

Property Value

TypeDefaultDescription
Booleanfalse

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

|

Remarks

Use the Expanded property to expand or collapse a node.

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 methodClient methodDescribtion
ASPxTreeView.ExpandAllASPxClientTreeView.ExpandAllExpands all nodes
ASPxTreeView.CollapseAllASPxClientTreeView.CollapseAllCollapses all nodes
ASPxTreeView.ExpandToDepthNoneExpands all nodes to the specified depth

Example

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

aspx
<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"
    XPath="/mainmenu/item"></asp:XmlDataSource>
csharp
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;
                break;
            }
            node = node.Parent;
        }
    }
}
vb
Protected Sub ASPxTreeView1_ExpandedChanging(ByVal source As Object, ByVal e As DevExpress.Web.ASPxTreeView.TreeViewNodeCancelEventArgs)
    e.Node.Expanded = True
    If e.Node.Expanded AndAlso (ASPxTreeView1.SelectedNode IsNot Nothing) Then
        Dim node As TreeViewNode = ASPxTreeView1.SelectedNode.Parent
        Do While node IsNot Nothing
            If e.Node Is node Then
                e.Cancel = True
                Exit Do
            End If
            node = node.Parent
        Loop
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Expanded property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

asp-net-web-forms-implement-sidebar-navigation/CS/AdaptiveSlideNavigation/UserControls/Navigation.ascx.cs#L20

csharp
NavigationTreeView.ExpandToNode(node);
node.Expanded = true;
while(node != null) {

asp-net-web-forms-implement-sidebar-navigation/VB/AdaptiveSlideNavigation/UserControls/Navigation.ascx.vb#L24

vb
NavigationTreeView.ExpandToNode(node)
node.Expanded = True
Do While node IsNot Nothing

See Also

Expanding and Collapsing Nodes

Member Table: Expanding and Collapsing Nodes

Tree View

TreeViewNode Class

TreeViewNode Members

DevExpress.Web Namespace