ListItemCollection.GetEnumerator 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.
Returns a IEnumerator implemented object that contains all ListItem objects in the ListItemCollection.
public:
virtual System::Collections::IEnumerator ^ GetEnumerator();
public System.Collections.IEnumerator GetEnumerator ();
abstract member GetEnumerator : unit -> System.Collections.IEnumerator
override this.GetEnumerator : unit -> System.Collections.IEnumerator
Public Function GetEnumerator () As IEnumerator
Returns
A IEnumerator implemented object that contains all ListItem objects in the ListItemCollection.
Implements
Examples
void allItems_Click(Object sender,EventArgs e)
{
IEnumerator dataListEnumerator;
DataListItem currentItem;
lblAllItems.Text = "";
// Get an enumerator to traverse the DataListItemCollection.
dataListEnumerator = myDataList.Items.GetEnumerator();
while(dataListEnumerator.MoveNext())
{
currentItem = (DataListItem)dataListEnumerator.Current;
// Display the current DataListItem onto the label.
lblAllItems.Text += ((Label)(currentItem.Controls[1])).Text + " ";
}
}
Sub AllItems_Click(sender As Object, e As EventArgs)
Dim dataListEnumerator As IEnumerator
Dim currentItem As DataListItem
lblAllItems.Text = ""
' Get an enumerator to traverse the DataListItemCollection.
dataListEnumerator = myDataList.Items.GetEnumerator()
while(dataListEnumerator.MoveNext())
currentItem = CType(dataListEnumerator.Current,DataListItem)
' Display the current DataListItem onto the label.
lblAllItems.Text = lblAllItems.Text & CType((currentItem.Controls(1)), _
Label).Text & " "
End While
End Sub
Remarks
Use this method to create a System.Collections.IEnumerator that can be iterated through to get each ListItem object in the ListItemCollection.
Use the IEnumerator.Current property to get the item currently pointed to in the collection.
Use the IEnumerator.MoveNext method to move to the next item in the collection.
Use the IEnumerator.Reset method to move the enumerator back to the initial position.
Note
After you create a System.Collections.IEnumerator object or use the IEnumerator.Reset method to move the enumerator to the first item in the collection, you must call the IEnumerator.MoveNext method. Otherwise, the item represented by the IEnumerator.Current property is undefined.
Applies to
See also
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應