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

Dim instance As TreeNodeCollection Dim nodeArray As TreeNode() Dim index As Integer instance.CopyTo(nodeArray, index)

CopyTo メソッドを使用して、TreeNodeCollection の内容を、インデックス番号が 0 から始まる指定した System.Array オブジェクトにコピーします。項目は、コピー先の配列の指定されたインデックス位置からコピーされます。System.Array オブジェクトを指定すると、配列の構文を使用して、TreeNodeCollection 内の項目にアクセスできます。
または、GetEnumerator メソッドを使用して、コレクション内の項目にアクセスするための列挙子を作成することもできます。

CopyTo メソッドを使用して、配列に TreeNodeCollection の値をコピーする方法の例を次に示します。Nodes プロパティは、TreeNodeCollection オブジェクトを返します。
<%@ 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, display the ' text value of each node. If LinksTreeView.Nodes.Count > 0 Then ' Declare an array of TreeNode objects. Dim RootNodeArray(LinksTreeView.Nodes.Count - 1) As TreeNode ' Use the CopyTo method to copy the root nodes into the array. LinksTreeView.Nodes.CopyTo(RootNodeArray, 0) ' Display the root nodes. Dim node As TreeNode For Each node In RootNodeArray Message.Text &= node.Text & "<br>" Next node Else Message.Text = "The TreeView control does not have any nodes." End If End Sub </script> <html> <body> <form runat="server"> <h3>TreeNodeCollection CopyTo 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, display the // text value of each node. if (LinksTreeView.Nodes.Count > 0) { // Declare an array of TreeNode objects. TreeNode[] RootNodeArray = new TreeNode[LinksTreeView.Nodes.Count]; // Use the CopyTo method to copy the root nodes into the array. LinksTreeView.Nodes.CopyTo(RootNodeArray, 0); // Display the root nodes. foreach (TreeNode node in RootNodeArray) { Message.Text += node.Text + "<br>"; } } else { Message.Text = "The TreeView control does not have any nodes."; } } </script> <html> <body> <form runat="server"> <h3>TreeNodeCollection CopyTo 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TreeNodeCollection.CopyTo メソッド
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As TreeNodeCollection Dim dest As Array Dim index As Integer instance.CopyTo(dest, index)

TreeNodeCollection の TreeNode オブジェクトの数を表示し、コレクションの内容を Object 配列にコピーして、ツリー ノードのリストを Label コントロールに表示するコード例を次に示します。この例は、少なくとも 1 つの TreeNode が TreeView の TreeNodeCollection にあること、および Label コントロールが Form に配置されていることを前提にしています。
Private Sub CopyTreeNodes() ' Get the collection of TreeNodes. Dim myNodeCollection As TreeNodeCollection = myTreeView.Nodes Dim myCount As Integer = myNodeCollection.Count myLabel.Text += "Number of nodes in the collection :" + myCount.ToString() myLabel.Text += ControlChars.NewLine + ControlChars.NewLine + _ "Elements of the Array after Copying from the collection :" + ControlChars.NewLine ' Create an Object array. Dim myArray(myCount -1) As Object ' Copy the collection into an array. myNodeCollection.CopyTo(myArray, 0) Dim i As Integer For i = 0 To myArray.Length - 1 myLabel.Text += CType(myArray(i), TreeNode).Text + ControlChars.NewLine Next i End Sub
private void CopyTreeNodes() { // Get the collection of TreeNodes. TreeNodeCollection myNodeCollection = myTreeView.Nodes; int myCount = myNodeCollection.Count; myLabel.Text += "Number of nodes in the collection :" + myCount; myLabel.Text += "\n\nElements of the Array after Copying from the collection :\n"; // Create an Object array. Object[] myArray = new Object[myCount]; // Copy the collection into an array. myNodeCollection.CopyTo(myArray,0); for(int i=0; i<myArray.Length; i++) { myLabel.Text += ((TreeNode)myArray[i]).Text + "\n"; } }
void CopyTreeNodes() { // Get the collection of TreeNodes. TreeNodeCollection^ myNodeCollection = myTreeView->Nodes; int myCount = myNodeCollection->Count; myLabel->Text = String::Concat( myLabel->Text, "Number of nodes in the collection : ", myCount ); myLabel->Text = String::Concat( myLabel->Text, "\n\nElements of the Array after Copying from the collection :\n" ); // Create an Object array. array<Object^>^myArray = gcnew array<Object^>(myCount); // Copy the collection into an array. myNodeCollection->CopyTo( myArray, 0 ); for ( int i = 0; i < myArray->Length; i++ ) { myLabel->Text = myLabel->Text + (dynamic_cast<TreeNode^>(myArray[ i ]))->Text + "\n"; } }
private void CopyTreeNodes() { // Get the collection of TreeNodes. TreeNodeCollection myNodeCollection = myTreeView.get_Nodes(); int myCount = myNodeCollection.get_Count(); myLabel.set_Text(myLabel.get_Text() + "Number of nodes in the collection :" + myCount); myLabel.set_Text(myLabel.get_Text() + "\n\nElements of the Array after Copying from the collection :\n"); // Create an Object array. Object myArray[] = new Object[myCount]; // Copy the collection into an array. myNodeCollection.CopyTo(myArray, 0); for (int i = 0; i < myArray.length; i++) { myLabel.set_Text(myLabel.get_Text() + ((TreeNode)myArray[i]).get_Text() + "\n"); } } //CopyTreeNodes

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

- TreeNodeCollection.CopyToのページへのリンク