CurrencyManager.List Właściwość

Definicja

Pobiera listę dla tego CurrencyManagerelementu .

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

Wartość właściwości

Element IList zawierający listę.

Przykłady

Poniższy przykład kodu umożliwia użytkownikom edytowanie zestawu rekordów, ale nie dodawanie nowych. Navigate W przypadku kontrolki DataGridIList zwracany przez List właściwość jest rzutowany do zmiennejDataView. Właściwość AllowNew właściwości DataView jest ustawiona na falsewartość .

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

Uwagi

Obiekt zwracany przez List właściwość może być rzutowany do dowolnego typu, który implementuje IList interfejs. Będzie to często używane, gdy znasz typ bazowej listy. Jeśli na przykład dane są powiązane z elementem DataSet, lista bazowa to DataView wartość (która implementuje IListelement ). Inne klasy implementujące interfejs (nie jest to pełna lista) obejmują Array, ArrayListi CollectionBase.

Sposób używania List właściwości zależy od klasy, która implementuje IList interfejs. Na przykład możesz użyć List właściwości , aby określić nazwę listy. Jeśli źródło danych implementuje ITypedList interfejs, możesz użyć GetListName metody , aby zwrócić nazwę bieżącej tabeli. Jest to pokazane w poniższym kodzie języka 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));   
}  

Dotyczy

Zobacz też