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

Dim instance As HtmlTableCellCollection Dim array As Array Dim index As Integer instance.CopyTo(array, index)

このメソッドを使用すると、HtmlTableCellCollection コレクションの内容が、指定された System.Array にコピーされます。コピーは指定した配列のインデックス位置から開始します。
![]() |
---|

CopyTo メソッドを使用して、HtmlTableCellCollection コレクションと同じ内容を格納する配列を作成する方法を次のコード例に示します。その後、配列は反復処理され、HtmlTableCellCollection コレクションの内容が表示されます。
<%@ Page Language="VB" AutoEventWireup="True" %> <script runat="server"> Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs) Dim myCellArray(1) As HtmlTableCell Dim cell As HtmlTableCell ' Copy the collection to an array. Table1.Rows(0).Cells.CopyTo(myCellArray, 0) Span1.InnerText = "The copied items from the selected row are: " ' Iterate through the array and display its contents. For Each cell In myCellArray Span1.InnerText = Span1.InnerText & " " & cell.InnerText Next cell End Sub </script> <html> <head> <title>HtmlTableCellCollection Example</title> </head> <body> <form runat="server"> <h3>HtmlTableCellCollection Example</h3> <table id="Table1" border="1" bordercolor="black" runat="server"> <tr> <td> Cell 1 </td> <td> Cell 2 </td> </tr> <tr> <td> Cell 3 </td> <td> Cell 4 </td> </tr> </table> <br><br> <input type="button" value="Display the contents of the first row" onserverclick="Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <script runat="server"> void Button_Click(Object sender, EventArgs e) { HtmlTableCell[] myCellArray = new HtmlTableCell[2]; // Copy the collection to an array. Table1.Rows[0].Cells.CopyTo(myCellArray, 0); Span1.InnerText = "The copied items from the selected row are: "; // Iterate through the array and display its contents. foreach (HtmlTableCell cell in myCellArray) { Span1.InnerText = Span1.InnerText + " " + cell.InnerText; } } </script> <html> <head> <title>HtmlTableCellCollection Example</title> </head> <body> <form runat="server"> <h3>HtmlTableCellCollection Example</h3> <table id="Table1" border="1" bordercolor="black" runat="server"> <tr> <td> Cell 1 </td> <td> Cell 2 </td> </tr> <tr> <td> Cell 3 </td> <td> Cell 4 </td> </tr> </table> <br><br> <input type="button" value="Display the contents of the first row" onserverclick="Button_Click" runat="server"/> <br><br> <span id="Span1" runat="server"/> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <script runat="server"> function Button_Click(sender, e : EventArgs) { var myCellArray : HtmlTableCell[] = new HtmlTableCell[2]; // Copy the collection to an array. Table1.Rows[0].Cells.CopyTo(myCellArray, 0); Span1.InnerText = "The copied items from the selected row are: "; // Iterate through the array and display its contents. for (var i : int in myCellArray) { Span1.InnerText = Span1.InnerText + " " + myCellArray[i].InnerText; } } </script> <html> <head> <title>HtmlTableCellCollection Example</title> </head> <body> <form runat="server"> <h3>HtmlTableCellCollection Example</h3> <table id="Table1" border="1" bordercolor="black" runat="server"> <tr> <td> Cell 1 </td> <td> Cell 2 </td> </tr> <tr> <td> Cell 3 </td> <td> Cell 4 </td> </tr> </table> <br><br> <input type="button" value="Display the contents of the first row" onserverclick="Button_Click" runat="server"/> <br><br> <span id="Span1" 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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- HtmlTableCellCollection.CopyTo メソッドのページへのリンク