指定した System.Array に ListItemCollection の項目をコピーします。コピー操作は、指定したインデックス位置から始まります。
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
ListItemCollection の項目のコピー先となる、インデックス番号が 0 から始まる System.Array 。 - index
項目のコピー先として指定されている System.Array の最初のインデックス。
実装
解説
このメソッドを使用して、指定した System.Array に ListItemCollection の内容をコピーします。コピー操作は、指定したインデックス位置から始まります。
メモ array パラメータには、インデックス番号が 0 から始まる System.Array を指定する必要があります。
使用例
' Copy the items in the ListListBox1.Items to an array before
' deleting them.
Dim myListItemArray(ListBox1.Items.Count - 1) As ListItem
ListBox1.Items.CopyTo(myListItemArray, 0)
' Delete all the items from the ListBox.
ListBox1.Items.Clear()
DeleteLabel.Text = "<b>All items in the ListBox were deleted successfully." +
"</b><br><b>The deleted items are:"
Dim listResults As [String] = ""
Dim myItem2 As ListItem
For Each myItem2 In myListItemArray
listResults = listResults & myItem2.Text & "<br>"
Next myItem2
ResultsLabel.Text = listResults
[C#]
// Copy the items in the ListItemCollection to an array before
// deleting them.
ListItem[] myListItemArray = new ListItem[ListBox1.Items.Count];
ListBox1.Items.CopyTo(myListItemArray, 0);
// Delete all the items from the ListBox.
ListBox1.Items.Clear();
DeleteLabel.Text = "<b>All items in the ListBox were deleted successfully."
+ "</b><br><b>The deleted items are:";
String listResults="";
foreach(ListItem myItem in myListItemArray)
{
listResults = listResults + myItem.Text + "<br>";
}
ResultsLabel.Text = listResults;
[C++, JScript] C++ および JScript のサンプルはありません。Visual Basic および C# のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
参照
ListItemCollection クラス | ListItemCollection メンバ | System.Web.UI.WebControls 名前空間 | System.Array