是否有一种简单的方法可以将节点添加到WinForms .NET TreeView控件中,在该控件中,将要添加的新节点插入到正确的索引处,因此整个节点列表将按字母顺序排序?与TreeView.Sort()
具有几乎相同的结果。
我有一个TreeView,它会不断增长到几百个节点。用户可以实时查看此TreeView的增长情况。我宁愿只是将节点插入正确的索引,而不是每次添加节点后都调用TreeView.Sort()。
能做到吗?
最佳答案
在winforms中,您可以简单地将TreeView的.Sorted
属性设置为True
。
When Sorted is set to true, the TreeNode objects are sorted in alphabetical order by their Text property values. You should always use BeginUpdate and EndUpdate to maintain performance when adding a large quantity of items to a sorted TreeView. When the text of an existing node is changed, you must call Sort to resort the items.
引用MSDN
关于.net - 添加节点后自动对TreeView进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/390802/