I've had a lot of trouble figuring out how to use devexpress's ASPxTreeList in virtual mode, and after a lot of back-and-forth with the support team, I finally got a simple test one to work. Now that I think about it, if I just tried to copy their example, it probably would have worked right away, but either way, I didn't truly understand it until now, so let me share what I've learned.
- You assign an event handler to each virtual mode event. You must do this before adding tree list to Controls.
- Don't add any nodes manually, e.g., by AppendNode.
- VirtualModeCreateChildren will fire once for the root node. Set the e.Children to the top level nodes.
- VirtualModeNodeCreating will fire once for each object in root node children. Set the e.NodeKeyValue to a unique value, but it must remain the same value for the entire life of the tree list. Also set the node column/field values here.
- The page is rendered. The user now sees the top level nodes in the tree.
- The user clicks the plus (+) to expand a node.
- VirtualModeCreateChildren fires once for the root node. Set the e.Children to the top level nodes.
- VirtualModeNodeCreating will fire once for each object in root node children. Set the e.NodeKeyValue to the same unique value as before. Also set the column/field values again.
- VirtualModeCreateChildren fires again for the node being expanded. e.NodeObject is not null this time, it contains the value you assigned to the expanded node. Set e.Children to the subnodes.
- VirtualModeNodeCreating fires once for each subnode. Set their keys and values. The keys must be unique and remain the same for the life of the tree list.
You have to build the tree anew each time from the root, down to the subnodes of the last expanded node.