通过


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控件,DataGridIList属性List返回的返回结果将强制转换为DataView变量。 AllowNewDataView 属性设置为 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 类型。 当你知道基础列表的类型时,通常会使用此类型。 例如,如果数据绑定到 aDataSet,则基础列表是一个DataView(实现)。IList 实现接口的其他类(这不是完整列表)包括 ArrayArrayList以及 CollectionBase

使用属性 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));
}

适用于

另请参阅