Load on demand

By default, when you add an existing node to the treeview, it becomes a part of the treeview hierarchy and will always be displayed in it. There are occasions when you will know which nodes will be displayed in the tree only during run-time. In this case, you will benefit from the mode of loading node's child nodes on demand, i.e., only when children are needed. Typically, this mode is useful when you need to fill subnodes only when the parent node is expanded.

To activate this mode, you must enable the LoadOnDemand property of the parent node and subscribe to the NodeExpanding treeview event, which is raised upon the node expansion. In the event handler, you have to add subnodes to the expanded node and, optionally, disable the LoadOnDemand property if the subnodes list won't alter anymore.

Example

Node someRootNode = tree.Nodes[0];
someRootNode.LoadOnDemand = true;
tree.NodeExpanding += new TreeEventHandler<NodeExpandingEventArgs>(tree_NodeExpanding);

private void tree_NodeExpanding(FlexibleTreeView treeview, NodeExpandingEventArgs args)
{
    // disable parent node's load on demand.
    args.Node.LoadOnDemand = false;

    // fill children nodes.
    args.Node.Nodes.Add(new Node("Child node"));
}
Dim someRootNode As Node = tree.Nodes(0)
someRootNode.LoadOnDemand = True
tree.NodeExpanding += New TreeEventHandler(Of NodeExpandingEventArgs)(tree_NodeExpanding)

Private Sub tree_NodeExpanding(treeview As FlexibleTreeView, args As NodeExpandingEventArgs)
    ' disable parent node's load on demand.
    args.Node.LoadOnDemand = False

    ' fill children nodes.
    args.Node.Nodes.Add(New Node("Child node"))
End Sub

Note

The node with enabled LoadOnDemand property will always display the plus-minus sign (+), in order to allow the user to expand the node.