自定义Treeview的排序

| 我有一个树视图,需要根据每个节点的标签以及alpha beta进行排序。 例如: Node1,标签= A,文本=苹果 Node2,标签= B,文本=气球 Node3,标记= A,文本=帮助 我想对它进行排序,带有标签A的节点将是第一个,然后是带有标签B的节点。 但是,我希望包含标签A的节点从A到Z进行排序。 (顺序= Node1,Node3,Node2) 请帮我 , 我该怎么做? 提前致谢!     
已邀请:
        假设您正在谈论System.Windows.Forms.Treeview,则可以使用TreeViewNodeSorter和IComparer的实现来创建自定义排序策略。 http://msdn.microsoft.com/zh-CN/library/system.windows.forms.treeview.treeviewnodesorter.aspx     
        谢谢!我这样做是这样的:
 /// <summary>
        ///  Create a node sorter that implements the IComparer interface.
       /// </summary>
        public class NodeSorter : IComparer
        {
            // compare between two tree nodes
            public int Compare(object thisObj, object otherObj)
            {
                TreeNode thisNode = thisObj as TreeNode;
                TreeNode otherNode = otherObj as TreeNode;

                // Compare the types of the tags, returning the difference.
                if (thisNode.Tag is  first_type&& otherNode.Tag is another_type)
                    return 1;
                 //alphabetically sorting
                return thisNode.Text.CompareTo(otherNode.Text);
            }
        } 
    

要回复问题请先登录注册