2

すべてのノードのタグに従って、またアルファベータに従ってソートする必要があるツリービューがあります。

例えば:

  • Node1、タグ = A、テキスト = Apple
  • Node2、タグ = B、テキスト =バルーン
  • Node3、タグ = A、テキスト =ヘルプ

タグAを持つノードが最初になり、次にタグBを持つノードになるように並べ替えたいのですが、タグAを含むノードをAからZに並べ替えたい.

(順序 = Node1,Node3,Node2 )

私を助けてください、どうすればいいですか?

前もって感謝します!

4

2 に答える 2

2

System.Windows.Forms.Treeview について話していると仮定すると、TreeViewNodeSorter と IComparer の実装を使用して、カスタムの並べ替え戦略を作成できます。

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.treeviewnodesorter.aspx

于 2011-06-21T21:12:18.257 に答える
0

ありがとう!私はそのようにしました:

 /// <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);
            }
        } 
于 2011-06-22T08:52:09.193 に答える