質問

I want to create an expandable empty treenode in C#, i.e. a treenode which is empty and has the [+] sign beside it. The reason is because initially it is empty, but once a node is clicked, I want to populate it with many child nodes.

The only problem I am facing is that empty treenodes aren't expandable, so I don't know what to do. Is there a way to solve this problem, or are there any workarounds?

役に立ちましたか?

解決

You have to redraw the tree itself, or create an empty node and simply remove it when the parent node is expanded.

Personally, I'd go for option b). I've done this before, a while ago and thanks to the events raised by the TreeView it pretty easy to accomplish. You can give the empty node a value like 'Loading...' so it gives some feedback to the user as well. :)

他のヒント

Add a dummy child node, and remove it when you expand.

Have a look at Josh Smiths excellent tutorial on treeviews. It allows lazy loading of child tree nodes by having a dummy node that is removed upon expansion.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top