TreeNodeBindingCollection.CopyTo(TreeNodeBinding[], Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從目標陣列中的指定索引開始,從 TreeNodeBindingCollection 物件中,將所有項目複製至相容的一維陣列 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 物件之以零起始的陣列,接收複製自 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使用 方法,將 物件 bindingArray
的內容 TreeNodeBindingCollection 複製到 。 從 開始 index
複製專案。 然後,您可以使用 陣列來存取集合中的專案。
或者,您可以使用 GetEnumerator 方法來建立列舉值,以用來存取集合中的專案。