I need to populate the TreeNode.ChildNodes on the event of TreeView.TreeNodeExpanded. The problem is the node is empty before the event gets fired and it is not expandable in this case and there is no expand icon [+] showed next to it.
I want to make the node expandable in case its related object has some children without adding those children to the node.
I thought about adding a virtual child to the node and delete it when it is expanded. Are there any better options ??
Thank you.
Three steps to do the trick:
1 – Set the TreeView.ExpandDepth to 0. This eliminates the expansion of the added
TreeNodeobjects in theTreeViewand shows the expansion symbol [+] next to eachTreeNodethat has theTreeNode.PopulateOnDemandproperty set to true.2- Set the TreeNode.PopulateOnDemand to True for each branch
TreeNode. When theTreeNode.ChildNodescollection is empty, the expansion symbol [+] will be showed only next toTreeNodeobjects that hasTreeNode.PopulateOnDemandproperty set to true.3- Handle the TreeView.TreeNodePopulate event to poulate branch nodes on expansion. This event will be fired when a
TreeNode– with theTreeNode.PopulateOnDemandset to true – has been expanded right before theTreeView.TreeNodeExpandedevent gets fired.