Condividi tramite


CurrencyManager.List Proprietà

Definizione

Ottiene l'elenco per l'oggetto 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

Valore della proprietà

Oggetto IList contenente l'elenco.

Esempio

L'esempio di codice seguente consente agli utenti di modificare un set di record, ma non di aggiungerne di nuovi. Navigate In caso di controlloDataGrid, viene eseguito il List cast dell'oggetto IList restituito dalla proprietà a una DataView variabile. La proprietà AllowNew del DataView è impostata su 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

Commenti

È possibile eseguire il cast dell'oggetto List restituito dalla proprietà a qualsiasi tipo che implementa l'interfaccia IList . Questo verrà comunemente usato quando si conosce il tipo dell'elenco sottostante. Ad esempio, se si è associati a dati a un DataSetoggetto , l'elenco sottostante è un DataView oggetto (che implementa IList). Altre classi che implementano l'interfaccia (non è un elenco completo) includono Array, ArrayListe CollectionBase.

La modalità di utilizzo della List proprietà dipende dalla classe che implementa l'interfaccia IList . Ad esempio, è possibile utilizzare la List proprietà per determinare il nome dell'elenco. Se l'origine dati implementa l'interfaccia ITypedList , è possibile utilizzare il GetListName metodo per restituire il nome della tabella corrente. Questo è illustrato nel codice C# seguente:

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

Si applica a

Vedi anche