Share via


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,包含清單。

範例

下列程式碼範例可讓使用者編輯一組記錄,但不會新增任何記錄。 Navigate在 控制項的 事件 DataGrid 中, IList 屬性傳回的 List 會轉換成 DataView 變數。 DataViewAllowNew 屬性會設定為 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));   
}  

適用於

另請參閱