RadControls for WinForms

The Load On Demand feature helps reduce performance and memory costs incurred when all nodes are loaded at one time. To benefit from this feature, you just need to handle the NodesNeeded event. This event is fired when you try to expand a node. The event arguments of this event return contain the Parent node that you are trying to expand and the Nodes collection that you should fill with subnodes. The code snippet below demonstrates how you can handle the NodesNeeded event and load 50 nodes to any expanded node:

Copy[C#]
void radTreeView1_NodesNeeded(object sender, NodesNeededEventArgs e)
{
    if (e.Parent == null)
    {
        LoadRootNodes(e.Nodes);
        return;
    }

    for (int i = 0; i < 50; i++)
    {
        RadTreeNode childNode = new RadTreeNode(string.Format("Node{0}", i));
        e.Nodes.Add(childNode);
    }
}

void LoadRootNodes(IList<RadTreeNode> nodes)
{
    RadTreeNode mcNode = new RadTreeNode("My Computer");
    nodes.Add(mcNode);
}
Copy[VB.NET]
Private Sub radTreeView1_NodesNeeded(ByVal sender As Object, ByVal e As NodesNeededEventArgs)
    If e.Parent Is Nothing Then
        LoadRootNodes(e.Nodes)
        Return
    End If

    For i As Integer = 0 To 49
        Dim childNode As New RadTreeNode(String.Format("Node{0}", i))
        e.Nodes.Add(childNode)
    Next i
End Sub

Private Sub LoadRootNodes(ByVal nodes As IList(Of RadTreeNode))
    Dim mcNode As New RadTreeNode("My Computer")
    nodes.Add(mcNode)
End Sub