次の方法で共有


ListItemCollection.Clear メソッド

コレクションからすべての ListItem オブジェクトを削除します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public Sub Clear
'使用
Dim instance As ListItemCollection

instance.Clear
public void Clear ()
public:
virtual void Clear () sealed
public final void Clear ()
public final function Clear ()
適用できません。

解説

Clear メソッドを使用して、すべての ListItem オブジェクトを削除します。Count プロパティも 0 に設定されます。

注意に関するメモ注意 :

このメソッドを使用すると、すべての ListItem オブジェクトがコレクションから削除されます。この操作を元に戻すことはできません。

使用例

' 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
// 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;
// Copy the items in the ListItemCollection to an array before 
// deleting them.     
ListItem myListItemArray[] = new ListItem[ListBox1.get_Items().
    get_Count()];
ListBox1.get_Items().CopyTo(myListItemArray, 0);

// Delete all the items from the ListBox.
ListBox1.get_Items().Clear();
DeleteLabel.set_Text("<b>All items in the ListBox were " 
    + "deleted successfully." 
    + "</b><br /><b>The deleted items are:");
String listResults="";
System.Collections.IEnumerator myEnum = myListItemArray.
    GetEnumerator();
while(myEnum.MoveNext()) {
    ListItem myItem = (ListItem)myEnum.get_Current();
    listResults = listResults + myItem.get_Text() + "<br />";
}
ResultsLabel.set_Text(listResults);

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

ListItemCollection クラス
ListItemCollection メンバ
System.Web.UI.WebControls 名前空間
Add
AddRange
Insert
Remove
RemoveAt