TreeNodeCollection.AddAt メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As TreeNodeCollection Dim index As Integer Dim child As TreeNode instance.AddAt(index, child)

AddAt メソッドを使用して、指定した TreeNode オブジェクトを TreeNodeCollection の指定した 0 から始まるインデックス位置に挿入します。
![]() |
---|
TreeNodeCollection を使用すると、null 参照 (Visual Basic の場合は Nothing) だけでなく、複製した TreeNode オブジェクトも挿入できます。 |
または、Add メソッドを使用して、TreeNode オブジェクトを TreeNodeCollection の末尾に追加することもできます。

AddAt メソッドを使用して、プログラムでノードを TreeNodeCollection に追加する方法の例を次に示します。Nodes プロパティおよび ChildNodes プロパティは、それぞれ TreeNodeCollection オブジェクトを返します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Use the Add and Remove methods to programmatically ' remove the Appendix C node and replace it with a new ' node. LinksTreeView.Nodes.Remove(LinksTreeView.Nodes(3)) LinksTreeView.Nodes.Add(New TreeNode("New Appendix C")) ' Use the AddAt and RemoveAt methods to programmatically ' remove the Chapter One node and replace it with a new node. LinksTreeView.Nodes(0).ChildNodes.RemoveAt(0) LinksTreeView.Nodes(0).ChildNodes.AddAt(0, New TreeNode("New Chapter One")) ' Use the Clear method to remove all the child nodes of the ' Chapter Two node. LinksTreeView.Nodes(0).ChildNodes(1).ChildNodes.Clear() End If End Sub </script> <html> <body> <form runat="server"> <h3>TreeNodeCollection 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="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> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { if (!IsPostBack) { // Use the Add and Remove methods to programmatically // remove the Appendix C node and replace it with a new // node. LinksTreeView.Nodes.Remove(LinksTreeView.Nodes[3]); LinksTreeView.Nodes.Add(new TreeNode("New Appendix C")); // Use the AddAt and RemoveAt methods to programmatically // remove the Chapter One node and replace it with a new node. LinksTreeView.Nodes[0].ChildNodes.RemoveAt(0); LinksTreeView.Nodes[0].ChildNodes.AddAt(0, new TreeNode("New Chapter One")); // Use the Clear method to remove all the child nodes of the // Chapter Two node. LinksTreeView.Nodes[0].ChildNodes[1].ChildNodes.Clear(); } } </script> <html> <body> <form runat="server"> <h3>TreeNodeCollection 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="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> </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に収録されているすべての辞書からTreeNodeCollection.AddAt メソッドを検索する場合は、下記のリンクをクリックしてください。

- TreeNodeCollection.AddAt メソッドのページへのリンク