TreeNode.ChildNodes プロパティ
アセンブリ: System.Web (system.web.dll 内)

現在のノードの第 1 レベルの子ノードを格納する TreeNodeCollection。

ChildNodes プロパティを使用して、現在のノードの第 1 レベルの子ノードを格納する TreeNodeCollection コレクションを取得します。このコレクションは、通常、第 1 レベルのすべての子ノードを反復処理する場合、または現在のノードの特定の第 1 レベルの子ノードにアクセスする場合に使用されます。
ChildNodes プロパティは、現在のノードの第 1 レベルの子ノードをプログラムで管理する場合にも使用できます。コレクションの TreeNode オブジェクトを追加、挿入、削除、および取得できます。このコレクションに加えられた更新は、ページが次に更新されるときに TreeView コントロールに自動的に反映されます。
ツリーの下位にある子ノードにアクセスするには、次のレベルの子ノードの ChildNodes プロパティを使用してノード レベルを下位に移動します。

ChildNodes プロパティを使用してツリーを走査する方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' If the TreeView control contains any root nodes, perform a ' preorder traversal of the tree and display the text of each node. If LinksTreeView.Nodes.Count > 0 Then ' Iterate through the root nodes in the Nodes property. Dim i As Integer For i = 0 To LinksTreeView.Nodes.Count - 1 ' Display the nodes. DisplayChildNodeText(LinksTreeView.Nodes(i)) Next i Else Message.Text = "The TreeView control does not have any nodes." End If End Sub Sub DisplayChildNodeText(ByVal node As TreeNode) ' Display the node's text value. Message.Text &= node.Text & "<br>" ' Iterate through the child nodes of the parent node passed into ' this method and display their values. Dim i As Integer For i = 0 To node.ChildNodes.Count - 1 ' Recursively call the DisplayChildNodeText method to ' traverse the tree and display all the child nodes. DisplayChildNodeText(node.ChildNodes(i)) Next i End Sub </script> <html> <body> <form runat="server"> <h3>TreeNodeCollection Count Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" runat="server"> <LevelStyles> <asp:TreeNodeStyle ChildNodesPadding="10" Font-Bold="true" Font-Size="12pt" ForeColor="DarkGreen"/> <asp:TreeNodeStyle ChildNodesPadding="5" Font-Bold="true" Font-Size="10pt"/> <asp:TreeNodeStyle ChildNodesPadding="5" Font-UnderLine="true" Font-Size="10pt"/> <asp:TreeNodeStyle ChildNodesPadding="10" Font-Size="8pt"/> </LevelStyles> <Nodes> <asp:TreeNode Text="Table of Contents" Expanded="true"> <asp:TreeNode Text="Chapter One"> <asp:TreeNode Text="Section 1.0"> <asp:TreeNode Text="Topic 1.0.1"/> <asp:TreeNode Text="Topic 1.0.2"/> <asp:TreeNode Text="Topic 1.0.3"/> </asp:TreeNode> <asp:TreeNode Text="Section 1.1"> <asp:TreeNode Text="Topic 1.1.1"/> <asp:TreeNode Text="Topic 1.1.2"/> <asp:TreeNode Text="Topic 1.1.3"/> <asp:TreeNode Text="Topic 1.1.4"/> </asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="Chapter Two"> <asp:TreeNode Text="Section 2.0"> <asp:TreeNode Text="Topic 2.0.1"> <asp:TreeNode Text="Subtopic 1"/> <asp:TreeNode Text="Subtopic 2"/> </asp:TreeNode> <asp:TreeNode Text="Topic 2.0.2"/> </asp:TreeNode> </asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="Appendix A" /> <asp:TreeNode Text="Appendix B" /> <asp:TreeNode Text="Appendix C" /> </Nodes> </asp:TreeView> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // If the TreeView control contains any root nodes, perform a // preorder traversal of the tree and display the text of each node. if(LinksTreeView.Nodes.Count > 0) { // Iterate through the root nodes in the Nodes property. for(int i=0; i<LinksTreeView.Nodes.Count; i++) { // Display the nodes. DisplayChildNodeText(LinksTreeView.Nodes[i]); } } else { Message.Text = "The TreeView control does not have any nodes."; } } void DisplayChildNodeText(TreeNode node) { // Display the node's text value. Message.Text += node.Text + "<br>"; // Iterate through the child nodes of the parent node passed into // this method and display their values. for(int i=0; i<node.ChildNodes.Count; i++) { // Recursively call the DisplayChildNodeText method to // traverse the tree and display all the child nodes. DisplayChildNodeText(node.ChildNodes[i]); } } </script> <html> <body> <form runat="server"> <h3>TreeNodeCollection Count Example</h3> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" runat="server"> <LevelStyles> <asp:TreeNodeStyle ChildNodesPadding="10" Font-Bold="true" Font-Size="12pt" ForeColor="DarkGreen"/> <asp:TreeNodeStyle ChildNodesPadding="5" Font-Bold="true" Font-Size="10pt"/> <asp:TreeNodeStyle ChildNodesPadding="5" Font-UnderLine="true" Font-Size="10pt"/> <asp:TreeNodeStyle ChildNodesPadding="10" Font-Size="8pt"/> </LevelStyles> <Nodes> <asp:TreeNode Text="Table of Contents" Expanded="true"> <asp:TreeNode Text="Chapter One"> <asp:TreeNode Text="Section 1.0"> <asp:TreeNode Text="Topic 1.0.1"/> <asp:TreeNode Text="Topic 1.0.2"/> <asp:TreeNode Text="Topic 1.0.3"/> </asp:TreeNode> <asp:TreeNode Text="Section 1.1"> <asp:TreeNode Text="Topic 1.1.1"/> <asp:TreeNode Text="Topic 1.1.2"/> <asp:TreeNode Text="Topic 1.1.3"/> <asp:TreeNode Text="Topic 1.1.4"/> </asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="Chapter Two"> <asp:TreeNode Text="Section 2.0"> <asp:TreeNode Text="Topic 2.0.1"> <asp:TreeNode Text="Subtopic 1"/> <asp:TreeNode Text="Subtopic 2"/> </asp:TreeNode> <asp:TreeNode Text="Topic 2.0.2"/> </asp:TreeNode> </asp:TreeNode> </asp:TreeNode> <asp:TreeNode Text="Appendix A" /> <asp:TreeNode Text="Appendix B" /> <asp:TreeNode Text="Appendix C" /> </Nodes> </asp:TreeView> <br><br> <asp:Label id="Message" runat="server"/> </form> </body> </html>

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


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

- TreeNode.ChildNodes プロパティのページへのリンク