HtmlTableCellCollection から、指定した System.Array に項目をコピーします。コピーは System.Array 内の指定されたインデックス位置から開始します。
Public Overridable Sub CopyTo( _
ByVal array As Array, _ ByVal index As Integer _) Implements ICollection.CopyTo
[C#]
public virtual void CopyTo(Arrayarray,intindex);
[C++]
public: virtual void CopyTo(Array* array,intindex);
[JScript]
public function CopyTo(
array : Array,index : int);
パラメータ
- array
HtmlTableCellCollection の項目のコピー先の、インデックス番号が 0 から始まる System.Array 。 - index
項目のコピー先として指定されている System.Array の最初のインデックス。
実装
解説
このメソッドを使用すると、 HtmlTableCellCollection の内容が、指定された System.Array にコピーされます。コピーは指定した配列のインデックス位置から開始します。
メモ array パラメータには、インデックス番号が 0 から始まる System.Array を指定する必要があります。
使用例
[Visual Basic, C#, JScript] CopyTo メソッドを使用して、 HtmlTableCellCollection と同一の内容を格納している配列を作成する方法の例を次に示します。その後、配列は反復処理され、 HtmlTableCellCollection の内容が表示されます。
<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
<head>
<script runat="server">
Sub Button_Click(sender As Object, 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>
</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>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
<head>
<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>
</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>
[JScript]
<%@ Page Language="JScript" AutoEventWireup="True" %>
<html>
<head>
<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>
</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>
[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
HtmlTableCellCollection クラス | HtmlTableCellCollection メンバ | System.Web.UI.HtmlControls 名前空間 | System.Array