CurrencyManager.List CurrencyManager.List CurrencyManager.List CurrencyManager.List Property

定义

获得此 CurrencyManager 的列表。Gets the list for this 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

属性值

包含列表的 IListAn IList that contains the list.

示例

下面的代码示例允许用户编辑一组记录,但不是添加任何新的。The following code example allows users to edit a set of records, but not add any new ones. 在中Navigate的事件DataGrid控件,IList返回List属性强制转换为DataView变量。In the Navigate event of a DataGrid control, the IList returned by the List property is cast to a DataView variable. AllowNewDataView 属性设置为 falseThe AllowNew property of the DataView is set to 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接口。The object returned by the List property can be cast to any type that implements the IList interface. 这通常时将使用您知道基础列表的类型。This will be commonly used when you know the type of the underlying list. 例如,如果你是数据绑定到DataSet,基础列表是DataView(它可以实现IList)。For example, if you are data-bound to a DataSet, the underlying list is a DataView (which implements IList). 实现的接口 (这不是完整的列表) 的其他类包括ArrayArrayList,和CollectionBaseOther classes that implement the interface (this is not a complete list) include Array, ArrayList, and CollectionBase.

如何使用List属性依赖于实现的类IList接口。How you use the List property depends on the class that implements the IList interface. 例如,可以使用List属性来确定列表的名称。For example, you can use the List property to determine the name of the list. 如果数据源实现ITypedList接口,可以使用GetListName方法以返回当前表的名称。If the data source implements the ITypedList interface, you can use the GetListName method to return the name of the current table. 下面的 C# 代码所示:This is shown in the C# code below:

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));   
}  

适用于

另请参阅