.net - 添加节点后自动对TreeView进行排序

标签 .net winforms sorting treeview

是否有一种简单的方法可以将节点添加到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/

相关文章:

asp.net - Microsoft .NET Framework 4.6.2 开发包 Windows 10 Build 1607

winforms - 使用依赖注入(inject)的分层解决方案的 Visual Studio 项目中的接口(interface)放置位置

c# - 在 c# winform 应用程序中使用安装的字体时出现问题

具有空字段的 Java 比较器

objective-c - Objective C 中的桶排序实现

web.config 文件中的 C# 连接字符串

c# - 如何在不安装 Microsoft Lync 的情况下在我的业务应用程序中创建自定义 Lync 客户端?

c# - .NET Extension Objects with XSLT——如何遍历一个集合?

c# - Form.Move 和 Form.LocationChanged 有什么区别?

javascript - 如何根据日期属性之间的范围是否包含给定日期来过滤对象数组?