Condividi tramite


CurrencyManager Classe

Definizione

Gestisce un elenco di Binding oggetti.

public ref class CurrencyManager : System::Windows::Forms::BindingManagerBase
public class CurrencyManager : System.Windows.Forms.BindingManagerBase
type CurrencyManager = class
    inherit BindingManagerBase
Public Class CurrencyManager
Inherits BindingManagerBase
Ereditarietà
CurrencyManager

Esempio

Nell'esempio di codice seguente un TextBox controllo viene associato a una colonna in un DataTableoggetto , ottiene l'oggetto CurrencyManager per l'associazione e ne imposta la posizione.

CurrencyManager^ myCurrencyManager;
void BindControl( DataTable^ myTable )
{
   
   // Bind a TextBox control to a DataTable column in a DataSet.
   textBox1->DataBindings->Add( "Text", myTable, "CompanyName" );
   
   // Specify the CurrencyManager for the DataTable.
   this->myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[ myTable ]);
   
   // Set the initial Position of the control.
   this->myCurrencyManager->Position = 0;
}

void MoveNext( CurrencyManager^ myCurrencyManager )
{
   if ( myCurrencyManager->Position == myCurrencyManager->Count - 1 )
   {
      MessageBox::Show( "You're at end of the records" );
   }
   else
   {
      myCurrencyManager->Position += 1;
   }
}

void MoveFirst( CurrencyManager^ myCurrencyManager )
{
   myCurrencyManager->Position = 0;
}

void MovePrevious( CurrencyManager^ myCurrencyManager )
{
   if ( myCurrencyManager->Position == 0 )
   {
      MessageBox::Show( "You're at the beginning of the records." );
   }
   else
   {
      myCurrencyManager->Position -= 1;
   }
}

void MoveLast( CurrencyManager^ myCurrencyManager )
{
   myCurrencyManager->Position = myCurrencyManager->Count - 1;
}
private CurrencyManager myCurrencyManager;
 
 private void BindControl(DataTable myTable){
    // Bind a TextBox control to a DataTable column in a DataSet.
    textBox1.DataBindings.Add("Text", myTable, "CompanyName");
    // Specify the CurrencyManager for the DataTable.
    myCurrencyManager = (CurrencyManager)this.BindingContext[myTable];
    // Set the initial Position of the control.
    myCurrencyManager.Position = 0;
 }
 
 private void MoveNext(CurrencyManager myCurrencyManager){
    if (myCurrencyManager.Position == myCurrencyManager.Count - 1){
       MessageBox.Show("You're at end of the records");
    }
    else{
      myCurrencyManager.Position += 1;
    }
 }
 
 private void MoveFirst(CurrencyManager myCurrencyManager){
    myCurrencyManager.Position = 0;
 }
 
 private void MovePrevious(CurrencyManager myCurrencyManager ){
    if(myCurrencyManager.Position == 0) {
       MessageBox.Show("You're at the beginning of the records.");
    }   
    else{
       myCurrencyManager.Position -= 1;
    }
 }
 
 private void MoveLast(CurrencyManager myCurrencyManager){
    myCurrencyManager.Position = myCurrencyManager.Count - 1;
 }
' Place the next line into the Declarations section of the form.
 Private myCurrencyManager As CurrencyManager
 
 Private Sub BindControl(myTable As DataTable)
    ' Bind a TextBox control to a DataTable column in a DataSet.
    TextBox1.DataBindings.Add("Text", myTable, "CompanyName")
    ' Specify the CurrencyManager for the DataTable.
    myCurrencyManager = CType(me.BindingContext(myTable), CurrencyManager)
    ' Set the initial Position of the control.
    myCurrencyManager.Position = 0
 End Sub
 
 Private Sub MoveNext(myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Position = myCurrencyManager.Count - 1 Then 
       MessageBox.Show("You're at end of the records")
    Else
       myCurrencyManager.Position += 1
    End If
 End Sub
 
 Private Sub MoveFirst(myCurrencyManager As CurrencyManager)
    myCurrencyManager.Position = 0
 End Sub
 
 Private Sub MovePrevious(myCurrencyManager As CurrencyManager)
    If myCurrencyManager.Position = 0 Then
       MessageBox.Show("You're at the beginning of the records.")
    Else
       myCurrencyManager.Position -= 1
    End if
 End Sub
 
 Private Sub MoveLast(myCurrencyManager As CurrencyManager)
    myCurrencyManager.Position = myCurrencyManager.Count - 1
 End Sub

Commenti

Deriva CurrencyManager dalla BindingManagerBase classe . BindingContext Utilizzare per restituire un CurrencyManager oggetto o .PropertyManager L'oggetto effettivo restituito dipende dall'origine dati e dal membro dati passato alla Item[] proprietà dell'oggetto BindingContext. Se l'origine dati è un oggetto che può restituire solo una singola proprietà (anziché un elenco di oggetti), il tipo sarà .PropertyManager Ad esempio, se si specifica un TextBox come origine dati, verrà restituito un oggetto PropertyManager . Se, invece, l'origine dati è un oggetto che implementa l'interfaccia IList, IListSourceo IBindingList , verrà restituito un oggetto CurrencyManager .

La Current proprietà restituisce l'elemento corrente nell'elenco sottostante. Per modificare l'elemento corrente, impostare la Position proprietà su un nuovo valore. Il valore deve essere maggiore di 0 e deve essere minore del valore della Count proprietà.

Se l'origine dati sottostante implementa l'interfaccia IBindingList e la AllowNew proprietà è impostata su true, è possibile usare il AddNew metodo .

Campi

Nome Descrizione
finalType

Specifica il tipo di dati dell'elenco.

listposition

Specifica la posizione corrente dell'oggetto CurrencyManager nell'elenco.

onCurrentChangedHandler

Specifica il gestore eventi per l'evento CurrentChanged .

(Ereditato da BindingManagerBase)
onPositionChangedHandler

Specifica il gestore eventi per l'evento PositionChanged .

(Ereditato da BindingManagerBase)

Proprietà

Nome Descrizione
Bindings

Ottiene la raccolta di associazioni gestite.

(Ereditato da BindingManagerBase)
Count

Ottiene il numero di elementi nell'elenco.

Current

Ottiene l'elemento corrente nell'elenco.

IsBindingSuspended

Ottiene un valore che indica se l'associazione è sospesa.

(Ereditato da BindingManagerBase)
List

Ottiene l'elenco per l'oggetto CurrencyManager.

Position

Ottiene o imposta la posizione in cui ci si trova all'interno dell'elenco.

Metodi

Nome Descrizione
AddNew()

Aggiunge un nuovo elemento all'elenco sottostante.

CancelCurrentEdit()

Annulla l'operazione di modifica corrente.

CheckEmpty()

Genera un'eccezione se non è presente alcun elenco o l'elenco è vuoto.

EndCurrentEdit()

Termina l'operazione di modifica corrente.

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetItemProperties()

Ottiene l'insieme di descrittori di proprietà per l'elenco sottostante.

GetItemProperties(ArrayList, ArrayList)

Ottiene la raccolta di descrittori di proprietà per l'associazione utilizzando l'oggetto specificato ArrayList.

(Ereditato da BindingManagerBase)
GetItemProperties(Type, Int32, ArrayList, ArrayList)

Ottiene l'elenco delle proprietà degli elementi gestiti da questo BindingManagerBaseoggetto .

(Ereditato da BindingManagerBase)
GetListName(ArrayList)

Ottiene il nome dell'elenco che fornisce i dati per l'associazione utilizzando il set specificato di proprietà associate.

GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
OnBindingComplete(BindingCompleteEventArgs)

Genera l'evento BindingComplete.

(Ereditato da BindingManagerBase)
OnCurrentChanged(EventArgs)

Genera l'evento CurrentChanged.

OnCurrentItemChanged(EventArgs)

Genera l'evento CurrentItemChanged.

OnDataError(Exception)

Genera l'evento DataError.

(Ereditato da BindingManagerBase)
OnItemChanged(ItemChangedEventArgs)

Genera l'evento ItemChanged.

OnMetaDataChanged(EventArgs)

Genera l'evento MetaDataChanged.

OnPositionChanged(EventArgs)

Genera l'evento PositionChanged.

PullData()

Esegue il pull dei dati dal controllo associato a dati nell'origine dati, senza restituire informazioni.

(Ereditato da BindingManagerBase)
PushData()

Esegue il push dei dati dall'origine dati nel controllo associato a dati, senza restituire informazioni.

(Ereditato da BindingManagerBase)
Refresh()

Forza il ripopolamento dell'elenco associato a dati.

RemoveAt(Int32)

Rimuove l'elemento in corrispondenza dell'indice specificato.

ResumeBinding()

Riprende il data binding.

SuspendBinding()

Sospende il data binding per impedire alle modifiche di aggiornare l'origine dati associata.

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)
UpdateIsBinding()

Aggiorna lo stato dell'associazione.

Eventi

Nome Descrizione
BindingComplete

Si verifica al completamento di un'operazione di associazione dati.

(Ereditato da BindingManagerBase)
CurrentChanged

Si verifica quando l'elemento attualmente associato cambia.

(Ereditato da BindingManagerBase)
CurrentItemChanged

Si verifica quando lo stato dell'elemento attualmente associato cambia.

(Ereditato da BindingManagerBase)
DataError

Si verifica quando un oggetto Exception viene gestito automaticamente da BindingManagerBase.

(Ereditato da BindingManagerBase)
ItemChanged

Si verifica quando l'elemento corrente è stato modificato.

ListChanged

Si verifica quando l'elenco cambia o un elemento nell'elenco cambia.

MetaDataChanged

Si verifica quando i metadati dell'oggetto List sono stati modificati.

PositionChanged

Si verifica dopo la modifica del valore della Position proprietà.

(Ereditato da BindingManagerBase)

Si applica a

Vedi anche