通过比较 TreeView 节点的 Tag 属性对它们进行排序
我编写了一个比较器,我想在 TreeView 的父节点上实现它,但我需要比较的是 Node.Tag.ToString() 而不是它们文本
。据我所知,没有重载或其他函数可以使用 TreeView.Sort() 来执行此操作。
我想知道您是否有办法或解决方法?
I wrote a comparator and I want to implement it on parent nodes of a TreeView
but what I need to be compared is the Node.Tag.ToString()
and not by theire Text
. As far as I looked there is no overload or another function to do this using TreeView.Sort()
.
I wonder if you have a way or workaround in mind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有 IComparer,看起来您可以设置 TreeViewNodeSorter 属性,然后调用 Sort 让节点按照您的意愿排序。
基于该链接的示例 - 未尝试,没有空检查等,但它应该可以工作:
然后在您的设置中的某处
treeView1.TreeViewNodeSorter = new NodeSorter();
。If you have an IComparer, it looks like you can set the TreeViewNodeSorter property to it and then call Sort to have the nodes sorted as you wish.
Example based on that link - not tried, no null checks etc. but it should work:
Then
treeView1.TreeViewNodeSorter = new NodeSorter();
somewhere in your setup.