Share via


TreeNodeBindingCollection.CopyTo(TreeNodeBinding[], Int32) メソッド

定義

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

public:
 void CopyTo(cli::array <System::Web::UI::WebControls::TreeNodeBinding ^> ^ bindingArray, int index);
public void CopyTo (System.Web.UI.WebControls.TreeNodeBinding[] bindingArray, int index);
override this.CopyTo : System.Web.UI.WebControls.TreeNodeBinding[] * int -> unit
Public Sub CopyTo (bindingArray As TreeNodeBinding(), index As Integer)

パラメーター

bindingArray
TreeNodeBinding[]

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

index
Int32

コピーされた内容の格納を開始する bindingArray 内の位置。

次のコード例では、 メソッドを CopyTo 使用してコレクションの DataBindings 内容を配列にコピーする方法を示します。


<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  void Page_Load(Object sender, EventArgs e)
  {

    // Create an array of TreeNodeBinding objects and then use the
    // CopyTo method to copy the contents of the DataBindings collection
    // to the array.
    TreeNodeBinding[] bindings = new TreeNodeBinding[BookTreeView.DataBindings.Count];
    BookTreeView.DataBindings.CopyTo(bindings, 0);

    // Iterate through the array and display the value of the text field
    // property of each TreeNodeBinding object.
    MessageLabel.Text = "The field names for each node level are: <br/>";

    foreach (TreeNodeBinding binding in bindings)
    {

      MessageLabel.Text += binding.TextField + "<br/>";

    }

  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBindingCollection CopyTo Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBindingCollection CopyTo Example</h3>
    
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" 
            TextField="Subject"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
      <br/>
    
      <asp:Label id="MessageLabel" runat="server"/>
    
    </form>
  </body>
</html>

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' Create an array of TreeNodeBinding objects and then use the
    ' CopyTo method to copy the contents of the DataBindings collection
    ' to the array.
    Dim bindings(BookTreeView.DataBindings.Count - 1) As TreeNodeBinding
    BookTreeView.DataBindings.CopyTo(bindings, 0)

    ' Iterate through the array and display the value of the text field
    ' property of each TreeNodeBinding object.
    MessageLabel.Text = "The field names for each node level are: <br/>"

    
    Dim binding As TreeNodeBinding
    For Each binding In bindings

      MessageLabel.Text &= binding.TextField & "<br/>"

    Next

  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head runat="server">
    <title>TreeNodeBindingCollection CopyTo Example</title>
</head>
<body>
    <form id="form1" runat="server">
    
      <h3>TreeNodeBindingCollection CopyTo Example</h3>
    
      <asp:TreeView id="BookTreeView" 
         DataSourceID="BookXmlDataSource"
         runat="server">
         
        <DataBindings>
          <asp:TreeNodeBinding DataMember="Book" 
            TextField="Title"/>
          <asp:TreeNodeBinding DataMember="Chapter" 
            TextField="Heading"/>
          <asp:TreeNodeBinding DataMember="Section" 
            TextField="Subject"/>
        </DataBindings>
         
      </asp:TreeView>
      
      <asp:XmlDataSource id="BookXmlDataSource"  
         DataFile="Book.xml"
         runat="server">
      </asp:XmlDataSource>
    
      <br/>
    
      <asp:Label id="MessageLabel" runat="server"/>
    
    </form>
  </body>
</html>

注釈

オブジェクトの CopyTo 内容を にコピーするには、 メソッドを TreeNodeBindingCollection 使用します bindingArray。 項目は からコピーされます index。 その後、 配列を使用して、コレクション内の項目にアクセスできます。

別の方法として、 メソッドを GetEnumerator 使用して、コレクション内の項目にアクセスするために使用できる列挙子を作成できます。

適用対象

こちらもご覧ください