TreeViewExtension.BindToVirtualData(TreeViewVirtualModeCreateChildrenMethod) Method

Allows creation of treeview nodes on demand (virtual mode).

Namespace: DevExpress.Web.Mvc

Assembly: DevExpress.Web.Mvc5.v21.1.dll


public TreeViewExtension BindToVirtualData(
    TreeViewVirtualModeCreateChildrenMethod method


Name Type Description
method TreeViewVirtualModeCreateChildrenMethod

A delegate method of the TreeViewVirtualModeCreateChildrenMethod type that enables you to create a list of business objects that correspond to the child nodes owned by the processed node.


Type Description

A TreeViewExtension object that is the TreeView.


In addition to bound and unbound modes, the TreeView extension can operate in a Virtual Mode, which greatly reduces both the server load and start-up time when working with complex or dynamically created data. In virtual mode, a tree is created on demand. In this instance, child nodes are created and initialized when their parent node is expanded.

To implement a virtual mode for the TreeView extension, you should use a specifically parameterized BindToVirtualData method. The method’s parameter refers to the delegate method that can be declared as a static method within a model class. Within this delegate method, create a list of business objects that correspond to the child nodes owned by the processed node.


The TreeViewSettings.SyncSelectionMode property affects the TreeView extension behavior in virtual mode. To learn more see the Virtual Mode topic.


// Model (TreeViewVirtualModeHelper)

public class TreeViewVirtualModeHelper {
        const string FileImageUrl = "~/Content/TreeView/FileSystem/file.png";
        const string DirImageUrl = "~/Content/TreeView/FileSystem/directory.png";
        static HttpRequest Request { get { return HttpContext.Current.Request; } }

        public static void CreateChildren(TreeViewVirtualModeCreateChildrenEventArgs e) {
            string parentNodePath = string.IsNullOrEmpty(e.NodeName) ? Request.MapPath("~/") : e.NodeName;
            List<TreeViewVirtualNode> children = new List<TreeViewVirtualNode>();
            if(Directory.Exists(parentNodePath)) {
                foreach(string childPath in Directory.GetDirectories(parentNodePath)) {
                    string childDirName = Path.GetFileName(childPath);
                    TreeViewVirtualNode childNode = new TreeViewVirtualNode(childPath, childDirName);
                    childNode.Image.Url = DirImageUrl;
                foreach(string childPath in Directory.GetFiles(parentNodePath)) {
                    string childFileName = Path.GetFileName(childPath);
                    TreeViewVirtualNode childNode = new TreeViewVirtualNode(childPath, childFileName);
                    childNode.IsLeaf = true;
                    childNode.Image.Url = FileImageUrl;
            e.Children = children;

        static bool IsSystemName(string name) {
            name = name.ToLower();
            return name.StartsWith("app_") || name == "bin" || name == "obj";
See Also