TreeViewNode.Expanded Property
Gets or sets whether the node is expanded.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v20.1.dll
NuGet Package: DevExpress.Web
Declaration
Property Value
Type | Default | Description |
---|---|---|
Boolean | false | 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 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 |
Example
The sample code below represents an ASPxTreeView.ExpandedChanging event handler. The event handler prevents collapsing nodes if it has selected children in any generation.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-prevent-parent-node-collapsing-e2439
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;
break;
}
node = node.Parent;
}
}
}
}
Related GitHub Examples
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.