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



Parent プロパティを使用して、現在のノードの親ノードの Text プロパティにアクセスする方法を次のコード例に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Selection_Changed(ByVal sender As Object, ByVal e As EventArgs) ' Display the selected node and its parent node. Message.Text = "You selected " & LinksTreeView.SelectedNode.Text & ". " If LinksTreeView.SelectedNode.Parent.Depth <> -1 Then Message.Text &= "Its parent node is " & LinksTreeView.SelectedNode.Parent.Text & "." Else Message.Text &= "This is a root node and does not have a parent node." End If End Sub </script> <html> <body> <form runat="server"> <h3>TreeNode Parent Example</h3> <h5>Select a node from the TreeView control.</h5> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" InitialExpandDepth="2" OnSelectedNodeChanged="Selection_Changed" 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"> <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="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 Selection_Changed(Object sender, EventArgs e) { // Display the selected node and its parent node. Message.Text = "You selected " + LinksTreeView.SelectedNode.Text + ". "; if(LinksTreeView.SelectedNode.Parent.Depth != -1) { Message.Text += "Its parent node is " + LinksTreeView.SelectedNode.Parent.Text + "."; } else { Message.Text += "This is a root node and does not have a parent node."; } } </script> <html> <body> <form runat="server"> <h3>TreeNode Parent Example</h3> <h5>Select a node from the TreeView control.</h5> <asp:TreeView id="LinksTreeView" Font-Name= "Arial" ForeColor="Blue" InitialExpandDepth="2" OnSelectedNodeChanged="Selection_Changed" 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"> <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="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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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



TreeView.SelectedNode の Parent プロパティが表す TreeNode の Index プロパティと Text プロパティの値を表示するコード例を次に示します。この例では、TreeView コントロールが配置された Form が存在している必要があります。TreeView コントロールは 2 つ以上のルート ノードを持ち、各ルート ノードに 1 つ以上の子ノードを持っている必要があります。
Private Sub treeView1_AfterSelect(sender As Object, _ e As TreeViewEventArgs) Handles treeView1.AfterSelect ' Display the Text and Index of the ' selected tree node's Parent. If (Not e.Node.Parent Is Nothing) If (e.Node.Parent.GetType() Is GetType(TreeNode)) Then statusBar1.Text = "Parent: " + e.Node.Parent.Text + _ ControlChars.Cr + "Index Position: " + e.Node.Parent.Index.ToString() End If Else statusBar1.Text = "No parent node." End If End Sub
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { /* Display the Text and Index of the * selected tree node's Parent. */ if(e.Node.Parent!= null && e.Node.Parent.GetType() == typeof(TreeNode) ) { statusBar1.Text = "Parent: " + e.Node.Parent.Text + "\n" + "Index Position: " + e.Node.Parent.Index.ToString(); } else { statusBar1.Text = "No parent node."; } }
private: void treeView1_AfterSelect( Object^ /*sender*/, TreeViewEventArgs^ e ) { /* Display the Text and Index of the * selected tree node's Parent. */ if ( e->Node->Parent != nullptr && e->Node->Parent->GetType() == TreeNode::typeid ) { statusBar1->Text = String::Format( "Parent: {0}\n Index Position: {1}", e->Node->Parent->Text, e->Node->Parent->Index ); } else { statusBar1->Text = "No parent node."; } }
private void treeView1_AfterSelect(Object sender, TreeViewEventArgs e) { /* Display the Text and Index of the selected tree node's Parent. */ if (e.get_Node().get_Parent() != null && e.get_Node().get_Parent(). GetType().Equals(TreeNode.class.ToType())) { statusBar1.set_Text("Parent: " + e.get_Node().get_Parent(). get_Text() + "\n" + "Index Position: " + System.Convert. ToString(e.get_Node().get_Parent().get_Index())); } else { statusBar1.set_Text("No parent node."); } } //treeView1_AfterSelect

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に収録されているすべての辞書からTreeNode.Parentを検索する場合は、下記のリンクをクリックしてください。

- TreeNode.Parentのページへのリンク