TreeNodeCollection.CopyToとは? わかりやすく解説

TreeNodeCollection.CopyTo メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

TreeNodeCollection オブジェクトすべての項目を互換性のある 1 次元TreeNode オブジェクト配列コピーしますコピー先の配列指定したインデックスからコピー開始されます。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub CopyTo ( _
    nodeArray As TreeNode(), _
    index As Integer _
)
Dim instance As TreeNodeCollection
Dim nodeArray As TreeNode()
Dim index As Integer

instance.CopyTo(nodeArray, index)
public void CopyTo (
    TreeNode[] nodeArray,
    int index
)
public:
void CopyTo (
    array<TreeNode^>^ nodeArray, 
    int index
)
public void CopyTo (
    TreeNode[] nodeArray, 
    int index
)
public function CopyTo (
    nodeArray : TreeNode[], 
    index : int
)

パラメータ

nodeArray

TreeNodeCollection の項目のコピー先となる、インデックス番号が 0 から始まる TreeNode オブジェクト配列

index

コピーされ内容格納される配列格納開始位置

解説解説
使用例使用例

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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
TreeNodeCollection クラス
TreeNodeCollection メンバ
System.Web.UI.WebControls 名前空間
TreeView
TreeNode クラス
System.Array
Item
ArrayList.CopyTo
GetEnumerator

TreeNodeCollection.CopyTo メソッド

コレクション全体既存配列内の指定した位置コピーします

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からTreeNodeCollection.CopyToを検索した結果を表示しています。
Weblioに収録されているすべての辞書からTreeNodeCollection.CopyToを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からTreeNodeCollection.CopyTo を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「TreeNodeCollection.CopyTo」の関連用語

TreeNodeCollection.CopyToのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



TreeNodeCollection.CopyToのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS