CurrencyManager.Count 属性

定义

获取列表中的项数。

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为减 1。

适用于

另请参阅