CurrencyManager.List 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此 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变量。
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 类型。 当你知道基础列表的类型时,通常会使用此类型。 例如,如果数据绑定到 aDataSet,则基础列表是一个DataView(实现)。IList 实现接口的其他类(这不是完整列表)包括 Array, ArrayList以及 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));
}