Skip to main content
Tab

TreeViewVirtualModeCreateChildrenEventArgs.Children Property

Gets or sets the collection of children for the currently processed node object.

Namespace: DevExpress.Web

Assembly: DevExpress.Web.v24.1.dll

NuGet Package: DevExpress.Web

Declaration

public IList<TreeViewVirtualNode> Children { get; set; }

Property Value

Type Description
IList<TreeViewVirtualNode>

The list of child nodes.

Remarks

Use the Children property to access a list of child objects owned by the processed node.

Example

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

<dx:ASPxTreeView ID="treeView" runat="server" EnableCallBacks="true" 
    OnVirtualModeCreateChildren="treeView_VirtualModeCreateChildren" />
using System.Collections.Generic;
using DevExpress.Web.ASPxTreeView;
using System.IO;

public partial class _Default : System.Web.UI.Page {
    const string FileImageUrl = "~/Images/file.png";
    const string DirImageUrl = "~/Images/directory.png";

    protected void Page_Load(object sender, EventArgs e) {
    }

    protected void treeView_VirtualModeCreateChildren(object source, TreeViewVirtualModeCreateChildrenEventArgs e) {
        string parentNodePath = string.IsNullOrEmpty(e.NodeName) ? Page.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);
                if (IsSystemName(childDirName))
                    continue;
                TreeViewVirtualNode childNode = new TreeViewVirtualNode(childPath, childDirName);
                childNode.Image.Url = DirImageUrl;
                children.Add(childNode);
            }
            foreach (string childPath in Directory.GetFiles(parentNodePath)) {
                string childFileName = Path.GetFileName(childPath);
                if (IsSystemName(childFileName))
                    continue;
                TreeViewVirtualNode childNode = new TreeViewVirtualNode(childPath, childFileName);
                childNode.IsLeaf = true;
                childNode.Image.Url = FileImageUrl;
                children.Add(childNode);
            }
        }
        e.Children = children;
    }

    protected bool IsSystemName(string name) {
        name = name.ToLower();
        return name.StartsWith("app_") || name == "bin"
            || name.EndsWith(".aspx.cs") || name.EndsWith(".aspx.vb");
    }
}
See Also