TreeNodeCollection.CopyTo(TreeNode[], Int32) Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Kopierar alla objekt från TreeNodeCollection objektet till en kompatibel endimensionell matris med TreeNode objekt, med början vid det angivna indexet i målmatrisen.
public:
void CopyTo(cli::array <System::Web::UI::WebControls::TreeNode ^> ^ nodeArray, int index);
public void CopyTo(System.Web.UI.WebControls.TreeNode[] nodeArray, int index);
member this.CopyTo : System.Web.UI.WebControls.TreeNode[] * int -> unit
Public Sub CopyTo (nodeArray As TreeNode(), index As Integer)
Parametrar
- nodeArray
- TreeNode[]
En nollbaserad matris med TreeNode objekt som tar emot de kopierade objekten TreeNodeCollectionfrån .
- index
- Int32
Positionen i målmatrisen där det kopierade innehållet ska börja tas emot.
Exempel
I följande exempel visas hur du använder CopyTo metoden för att kopiera värdena för en TreeNodeCollection till en matris. Observera att egenskapen Nodes returnerar ett TreeNodeCollection objekt.
<%@ 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)
{
// 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 xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeCollection CopyTo Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeCollection CopyTo Example</h3>
<asp:TreeView id="LinksTreeView"
Font-Names= "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="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)
' 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 xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TreeNodeCollection CopyTo Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>TreeNodeCollection CopyTo Example</h3>
<asp:TreeView id="LinksTreeView"
Font-Names= "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>
Kommentarer
CopyTo Använd metoden för att kopiera innehållet TreeNodeCollection i det angivna nollbaserade System.Array objektet. Objekt kopieras från och med det angivna indexet för målmatrisen. System.Array Med -objektet kan du sedan använda matrissyntax för att komma åt objekten TreeNodeCollectioni .
Alternativt kan du också använda GetEnumerator metoden för att skapa en uppräknare som kan användas för att komma åt objekten i samlingen.