共用方式為


CurrencyManager.List 屬性

定義

拿到這個 CurrencyManager清單。

public:
 property System::Collections::IList ^ List { System::Collections::IList ^ get(); };
public System.Collections.IList List { get; }
member this.List : System.Collections.IList
Public ReadOnly Property List As IList

屬性值

那個 IList 包含清單的那個。

範例

以下程式碼範例允許使用者編輯一組紀錄,但無法新增任何紀錄。 若有DataGrid控制項IList,屬性回傳List的 將Navigate被鑄造為變DataView數。 AllowNew 的屬性 DataView 被設定為 false

private:
   void Grid_Navigate( Object^ /*sender*/, NavigateEventArgs^ e )
   {
      if ( e->Forward )
      {
         DataSet^ ds = dynamic_cast<DataSet^>(grid->DataSource);
         CurrencyManager^ cm = dynamic_cast<CurrencyManager^>(BindingContext[ds, "Customers::CustOrders"]);
         
         // Cast the IList* to a DataView to set the AllowNew property.
         DataView^ dv = dynamic_cast<DataView^>(cm->List);
         dv->AllowNew = false;
      }
   }
private void Grid_Navigate(object sender, NavigateEventArgs e){
   if (e.Forward ){
      DataSet ds = (DataSet) grid.DataSource;
      CurrencyManager cm  = 
      (CurrencyManager)BindingContext[ds,"Customers.CustOrders"];
      // Cast the IList to a DataView to set the AllowNew property.
      DataView dv  = (DataView) cm.List;
      dv.AllowNew = false;
   }
}
Private Sub Grid_Navigate(sender As Object, e As NavigateEventArgs)
   If e.Forward Then
      Dim ds As DataSet = CType(grid.DataSource, DataSet)
      Dim cm As CurrencyManager = _
      CType(BindingContext(ds,"Customers.CustOrders"), CurrencyManager)
      ' Cast the IList to a DataView to set the AllowNew property.
      Dim dv As DataView = CType(cm.List, DataView)
      dv.AllowNew = false
   End If
End Sub

備註

屬性回傳 List 的物件可以被鑄造成任何實作該 IList 介面的型別。 當你知道底層清單的類型時,這通常會被使用。 例如,若你被資料綁定於 DataSet,底層清單為 DataView (實作 IList)。 其他實作該介面的類別(此非完整列表)包括 ArrayArrayListCollectionBase及 。

如何使用這個 List 屬性取決於實作介面 IList 的類別。 例如,你可以利用該 List 屬性來決定清單的名稱。 如果資料來源實作了介面, ITypedList 你可以用這個 GetListName 方法回傳目前資料表的名稱。 這點在下面的 C# 程式碼中有所展示:

private void PrintCurrentListName(DataGrid myDataGrid){
   CurrencyManager myCM = (CurrencyManager)
   BindingContext[myDataGrid.DataSource, myDataGrid.DataMember];
   IList myList = myCM.List;
   ITypedList thisList = (ITypedList) myList;
   Console.WriteLine(thisList.GetListName(null));
}

適用於

另請參閱