Skip to main content
Tab

TreeViewNode.Parent Property

Gets the immediate parent node to which the current node belongs.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v23.2.dll

NuGet Package: DevExpress.Web

Declaration

public TreeViewNode Parent { get; }

Property Value

Type Description
TreeViewNode

A TreeViewNode object representing the node’s immediate parent.

Remarks

Use the Parent property to identify and access the immediate parent node which owns the current node.

Example

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

<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>
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;
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Parent 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.

See Also