3

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.

3 Answers 3

3

Three steps to do the trick:

1 - Set the TreeView.ExpandDepth to 0. This eliminates the expansion of the added TreeNode objects in the TreeView and shows the expansion symbol [+] next to each TreeNode that has the TreeNode.PopulateOnDemand property set to true.

2- Set the TreeNode.PopulateOnDemand to True for each branch TreeNode. When the TreeNode.ChildNodes collection is empty, the expansion symbol [+] will be showed only next to TreeNode objects that has TreeNode.PopulateOnDemand property set to true.

3- Handle the TreeView.TreeNodePopulate event to poulate branch nodes on expansion. This event will be fired when a TreeNode - with the TreeNode.PopulateOnDemand set to true - has been expanded right before the TreeView.TreeNodeExpanded event gets fired.

Sign up to request clarification or add additional context in comments.

Comments

0

I suggest editing the template of the node. Have a look at An ASP.NET AJAX TreeView control with templates.

Comments

0

Not sure and do not have time to try but I guess what you are after is the TreeNode.PopulateOnDemand property and TreeView.TreeNodePopulate event.

1 Comment

I know that part.. I need to make the TreeNode expandable before populating its items if it has some.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.