ListItemCollection.Clear 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从集合中删除所有 ListItem 对象。
public:
virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()
实现
示例
// 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 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
注解
Clear使用该方法删除所有ListItem对象。 该 Count 属性也设置为 0
。
注意
使用此方法时,将从集合中删除所有 ListItem 对象。 无法撤消此操作。