ListItemCollection.Clear Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Removes all ListItem objects from the collection.
public:
virtual void Clear();
public void Clear ();
abstract member Clear : unit -> unit
override this.Clear : unit -> unit
Public Sub Clear ()
Implements
Examples
// 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
Remarks
Use the Clear method to remove all ListItem objects. The Count property is also set to 0
.
Caution
When you use this method, all ListItem objects are removed from the collection. You cannot undo this.
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET