CurrencyManager.Count 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得清單中的項目數。
public:
virtual property int Count { int get(); };
public override int Count { get; }
member this.Count : int
Public Overrides ReadOnly Property Count As Integer
屬性值
清單中的項目數目。
範例
下列程式碼範例會逐一查看清單,直到到達屬性所 Count 決定的最終專案為止。
void PrintListItems()
{
// Get the CurrencyManager of a TextBox control.
CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(textBox1->BindingContext[nullptr]);
// Presuming the list is a DataView, create a DataRowView variable.
DataRowView^ drv;
for ( int i = 0; i < myCurrencyManager->Count; i++ )
{
myCurrencyManager->Position = i;
drv = dynamic_cast<DataRowView^>(myCurrencyManager->Current);
// Presuming a column named CompanyName exists.
Console::WriteLine( drv[ "CompanyName" ] );
}
}
private void PrintListItems() {
// Get the CurrencyManager of a TextBox control.
CurrencyManager myCurrencyManager = (CurrencyManager)textBox1.BindingContext[0];
// Presuming the list is a DataView, create a DataRowView variable.
DataRowView drv;
for(int i = 0; i < myCurrencyManager.Count; i++) {
myCurrencyManager.Position = i;
drv = (DataRowView)myCurrencyManager.Current;
// Presuming a column named CompanyName exists.
Console.WriteLine(drv["CompanyName"]);
}
}
Private Sub PrintListItems()
' Get the CurrencyManager of a TextBox control.
Dim myCurrencyManager As CurrencyManager = CType(textBox1.BindingContext(0), CurrencyManager)
' Presuming the list is a DataView, create a DataRowView variable.
Dim drv As DataRowView
Dim i As Integer
For i = 0 To myCurrencyManager.Count - 1
myCurrencyManager.Position = i
drv = CType(myCurrencyManager.Current, DataRowView)
' Presuming a column named CompanyName exists.
Console.WriteLine(drv("CompanyName"))
Next i
End Sub
備註
使用 count 屬性來判斷清單的結尾何時到達。 CurrencyManager因為 會維護以 0 為基礎的專案陣列,所以清單結尾一律 Count 會減一。