TreeView.TreeViewNodeSorter プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As TreeView Dim value As IComparer value = instance.TreeViewNodeSorter instance.TreeViewNodeSorter = value
/** @property */ public IComparer get_TreeViewNodeSorter () /** @property */ public void set_TreeViewNodeSorter (IComparer value)
public function get TreeViewNodeSorter () : IComparer public function set TreeViewNodeSorter (value : IComparer)
カスタムの並べ替えを実行する IComparer。

カスタムの並べ替えは、TreeViewNodeSorter が設定されているときに適用されます。TreeViewNodeSorter プロパティが設定されると、Sorted プロパティは自動的に false に設定されます。
TreeViewNodeSorter を設定すると、Sorted プロパティが true に設定されている場合、ノードがアルファベット順に並べ替えられます。Sort メソッドを呼び出すと、TreeViewNodeSorter プロパティで指定したカスタムのソータを使用して、項目を再度並べ替えることができます。

TreeViewNodeSorter プロパティを使用して、ノードを最小から最大の順序で並べ替える方法を次のコード例に示します。この例を実行するには、次のコードを Windows フォームに貼り付け、フォームのコンストラクタまたは Load のイベント処理メソッドから、InitializeTreeView1 を呼び出します。
' Declare the TreeView. Private WithEvents treeView1 As TreeView Private textBox1 As TextBox Private WithEvents button1 As Button Private Sub InitializeTreeView1() ' Create the TreeView treeView1 = New TreeView() treeView1.Size = New Size(200, 200) ' Create the button and set some basic properties. button1 = New Button() button1.Location = New Point(205, 138) button1.Text = "Set Sorter" ' Handle the click event for the button. AddHandler button1.Click, AddressOf button1_Click ' Create the root nodes. Dim docNode As New TreeNode("Documents") Dim spreadSheetNode As New TreeNode("Spreadsheets") ' Add some additional nodes. spreadSheetNode.Nodes.Add("payroll.xls") spreadSheetNode.Nodes.Add("checking.xls") spreadSheetNode.Nodes.Add("tracking.xls") docNode.Nodes.Add("phoneList.doc") docNode.Nodes.Add("resume.doc") ' Add the root nodes to the TreeView. treeView1.Nodes.Add(spreadSheetNode) treeView1.Nodes.Add(docNode) ' Add the TreeView to the form. Controls.Add(treeView1) Controls.Add(button1) End Sub ' Set the TreeViewNodeSorter property to a new instance ' of the custom sorter. Private Sub button1_Click(ByVal sender As Object, _ ByVal e As EventArgs) Handles button1.Click treeView1.TreeViewNodeSorter = New NodeSorter() End Sub 'button1_Click ' Create a node sorter that implements the IComparer interface. Public Class NodeSorter Implements IComparer ' Compare the length of the strings, or the strings ' themselves, if they are the same length. Public Function Compare(ByVal x As Object, ByVal y As Object) _ As Integer Implements IComparer.Compare Dim tx As TreeNode = CType(x, TreeNode) Dim ty As TreeNode = CType(y, TreeNode) If tx.Text.Length <> ty.Text.Length Then Return tx.Text.Length - ty.Text.Length End If Return String.Compare(ty.Text, tx.Text) End Function End Class
// Declare the TreeView. private TreeView treeView1; private TextBox textBox1; private Button button1; private void InitializeTreeView1() { // Create the TreeView treeView1 = new TreeView(); treeView1.Size = new Size(200, 200); // Create the button and set some basic properties. button1 = new Button(); button1.Location = new Point(205, 138); button1.Text = "Set Sorter"; // Handle the click event for the button. button1.Click += new EventHandler(button1_Click); // Create the root nodes. TreeNode docNode = new TreeNode("Documents"); TreeNode spreadSheetNode = new TreeNode("Spreadsheets"); // Add some additional nodes. spreadSheetNode.Nodes.Add("payroll.xls"); spreadSheetNode.Nodes.Add("checking.xls"); spreadSheetNode.Nodes.Add("tracking.xls"); docNode.Nodes.Add("phoneList.doc"); docNode.Nodes.Add("resume.doc"); // Add the root nodes to the TreeView. treeView1.Nodes.Add(spreadSheetNode); treeView1.Nodes.Add(docNode); // Add the TreeView to the form. Controls.Add(treeView1); Controls.Add(button1); } // Set the TreeViewNodeSorter property to a new instance // of the custom sorter. private void button1_Click(object sender, EventArgs e) { treeView1.TreeViewNodeSorter = new NodeSorter(); } // Create a node sorter that implements the IComparer interface. public class NodeSorter : IComparer { // Compare the length of the strings, or the strings // themselves, if they are the same length. public int Compare(object x, object y) { TreeNode tx = x as TreeNode; TreeNode ty = y as TreeNode; // Compare the length of the strings, returning the difference. if (tx.Text.Length != ty.Text.Length) return tx.Text.Length - ty.Text.Length; // If they are the same length, call Compare. return string.Compare(ty.Text, tx.Text); } }
// Create a node sorter that implements the IComparer interface. private: ref class NodeSorter : public IComparer { // Compare the length of the strings, or the strings // themselves, if they are the same length. public: virtual int Compare(Object^ x, Object^ y) { TreeNode^ tx = (TreeNode^)x; TreeNode^ ty = (TreeNode^)y; // Compare the length of the strings, returning the difference. if (tx->Text->Length != ty->Text->Length) { return (tx->Text->Length - ty->Text->Length); } // If they are the same length, call Compare. return String::Compare(ty->Text, tx->Text); } }; // Declare the TreeView. private: TreeView^ initialTreeView; private: TextBox^ displayNodes; private: Button^ setSorter; private: void InitializeInitialTreeView() { // Create the TreeView initialTreeView = gcnew TreeView(); initialTreeView->Size = System::Drawing::Size(200, 200); // Create the button and set some basic properties. setSorter = gcnew Button(); setSorter->Location = Point(205, 138); setSorter->Text = "Set Sorter"; // Handle the click event for the button. setSorter->Click += gcnew EventHandler(this, &TreeViewWhidbeyMembersExample::SetSorter_Click); // Create the root nodes. TreeNode^ docNode = gcnew TreeNode("Documents"); TreeNode^ spreadSheetNode = gcnew TreeNode("Spreadsheets"); // Add some additional nodes. spreadSheetNode->Nodes->Add("payroll.xls"); spreadSheetNode->Nodes->Add("checking.xls"); spreadSheetNode->Nodes->Add("tracking.xls"); docNode->Nodes->Add("phoneList.doc"); docNode->Nodes->Add("resume.doc"); // Add the root nodes to the TreeView. initialTreeView->Nodes->Add(spreadSheetNode); initialTreeView->Nodes->Add(docNode); // Add the TreeView to the form. this->Controls->Add(initialTreeView); this->Controls->Add(setSorter); } // Set the TreeViewNodeSorter property to a new instance // of the custom sorter. private: void SetSorter_Click(Object^ sender, EventArgs^ e) { initialTreeView->TreeViewNodeSorter = gcnew NodeSorter(); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からTreeView.TreeViewNodeSorter プロパティを検索する場合は、下記のリンクをクリックしてください。

- TreeView.TreeViewNodeSorter プロパティのページへのリンク