ASPxTreeView.VirtualModeCreateChildren Event

Used to activate virtual mode. Occurs when expanding a node for the first time in this mode.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v20.2.dll


public event TreeViewVirtualModeCreateChildrenEventHandler VirtualModeCreateChildren

Event Data

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

Property Description
Children Gets or sets the collection of children for the currently processed node object.
NodeName Gets or sets the processed node's name.


In virtual mode, a tree is created on the server in portions on a client request, at start-up, and when expanding nodes. So, in virtual mode, child nodes are not created and initialized until their parent node is expanded for the first time.


The ASPxTreeView.SyncSelectionMode property affects the ASPxTreeView control behavior in virtual mode.

Handle the VirtualModeCreateChildren event to activate virtual mode for the ASPxTreeView. Within the event handler, you need to create a list of TreeViewVirtualNode objects specifying child nodes for the currently expanded node. If a child node has no children, set its TreeViewVirtualNode.IsLeaf property to true, to prevent showing the expand button for this node.


You can set a child node's TreeViewVirtualNode.Expanded property to true directly within a VirtualModeCreateChildren event handler to fire the event for this node. That way, you can expand only specific nodes or recursively expand nodes to a specific nesting level. To distinguish child nodes or their nesting levels, assign node names (TreeViewVirtualNode.Name property values) based on a parent node's name (TreeViewVirtualModeCreateChildrenEventArgs.NodeName).

Example 1

In this demo, the ASPxTreeView uses Virtual Mode to display the file/folder tree of the demo's web site.

View Example

<dx:ASPxTreeView ID="treeView" runat="server" EnableCallBacks="true" OnVirtualModeCreateChildren="treeView_VirtualModeCreateChildren">

Example 2

The following code snippet demonstrates how to handle the VirtualModeCreateChildren event to add child nodes based on the nesting level. Two child nodes are created for the root node (these child nodes are labeled 'Parent Node1' and 'Parent Node2') and nodes at the next nesting level only (these child nodes are labeled 'Child Node1' and 'Child Node2').

The initial node hierarchy will appear as follows.


// ...
    const string InitialNodeNamePrefix = "InitialNode";
    protected void ASPxTreeView1_VirtualModeCreateChildren(object source, DevExpress.Web.TreeViewVirtualModeCreateChildrenEventArgs e)
        List<TreeViewVirtualNode> nodes = new List<TreeViewVirtualNode>();

        // Populating nodes based on the currently processed parent node
        // identified by e.NodeName.
        if (e.NodeName == null)
            // Processing the root node.
            TreeViewVirtualNode initialNode1 = new TreeViewVirtualNode(InitialNodeNamePrefix + "1", "Parent Node1");
            initialNode1.Expanded = true;
            TreeViewVirtualNode initialNode2 = new TreeViewVirtualNode(InitialNodeNamePrefix + "2", "Parent Node2");
            initialNode2.Expanded = true;
            if (e.NodeName.StartsWith(InitialNodeNamePrefix))
                // Creating a unique child node name based on its parent node name.
                TreeViewVirtualNode childNode1 = new TreeViewVirtualNode("ChildNode1" + e.NodeName, "Child Node1");

                // Creating a unique child node name based on its parent node name.
                TreeViewVirtualNode childNode2 = new TreeViewVirtualNode("ChildNode2" + e.NodeName, "Child Node2");
                // Other chil