Empty expandable treenode in C#

走远了吗. 提交于 2019-12-08 03:58:31

问题


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?


回答1:


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. :)




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/8242647/empty-expandable-treenode-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!