BindingsCollection BindingsCollection BindingsCollection BindingsCollection Class

Definizione

Rappresenta un insieme di oggetti Binding di un controllo.Represents a collection of Binding objects for a control.

public ref class BindingsCollection : System::Windows::Forms::BaseCollection
public class BindingsCollection : System.Windows.Forms.BaseCollection
type BindingsCollection = class
    inherit BaseCollection
Public Class BindingsCollection
Inherits BaseCollection
Ereditarietà
Derivato

Esempi

Nell'esempio seguente la Text proprietà di un TextBox controllo viene associata a un campo in un database.The following example binds the Text property of a TextBox control to a field in a database.

private:
   void BindTextBoxControl()
   {
      DataSet^ myDataSet = gcnew DataSet;
      /* Insert code to populate the DataSet with tables, 
      columns, and data. */

      // Creates a new Binding object. 
      Binding^ myBinding = gcnew Binding(
         "Text",myDataSet,"customers.custToOrders.OrderAmount" );
      
      // Adds event delegates for the Parse and Format events.
      myBinding->Parse += gcnew ConvertEventHandler( this, &Form1::CurrencyToDecimal );
      myBinding->Format += gcnew ConvertEventHandler( this, &Form1::DecimalToCurrency );
      
      // Adds the new Binding to the BindingsCollection.
      text1->DataBindings->Add( myBinding );
   }

   void DecimalToCurrency( Object^ /*sender*/, ConvertEventArgs^ cevent )
   {
      /* This method is the Format event handler. Whenever the 
      control displays a new value, the value is converted from 
      its native Decimal type to a string. The ToString method 
      then formats the value as a Currency, by using the 
      formatting character "c". */
      cevent->Value = safe_cast<Decimal ^>(cevent->Value)->ToString(  "c" );
   }

   void CurrencyToDecimal( Object^ /*sender*/, ConvertEventArgs^ cevent )
   {
      /* This method is the Parse event handler. The Parse event 
      occurs whenever the displayed value changes. The static 
      Parse method of the Decimal structure converts the 
      string back to its native Decimal type. */
      cevent->Value = Decimal::Parse( cevent->Value->ToString(),
         NumberStyles::Currency, nullptr );
   }
private void BindTextBoxControl()
{
   DataSet myDataSet = new DataSet();
   /* Insert code to populate the DataSet with tables, 
   columns, and data. */

   // Creates a new Binding object. 
   Binding myBinding = new Binding
   ("Text", myDataSet, "customers.custToOrders.OrderAmount");

   // Adds event delegates for the Parse and Format events.
   myBinding.Parse += new ConvertEventHandler(CurrencyToDecimal);
   myBinding.Format += new ConvertEventHandler(DecimalToCurrency);

   // Adds the new Binding to the BindingsCollection.
   text1.DataBindings.Add(myBinding);
}

private void DecimalToCurrency(object sender, 
   ConvertEventArgs cevent)
{
   /* This method is the Format event handler. Whenever the 
   control displays a new value, the value is converted from 
   its native Decimal type to a string. The ToString method 
   then formats the value as a Currency, by using the 
   formatting character "c". */
   cevent.Value = ((decimal) cevent.Value).ToString("c");
}

private void CurrencyToDecimal(object sender, 
   ConvertEventArgs cevent)
{   
   /* This method is the Parse event handler. The Parse event 
   occurs whenever the displayed value changes. The static 
   Parse method of the Decimal structure converts the 
   string back to its native Decimal type. */
   cevent.Value = Decimal.Parse(cevent.Value.ToString(),
   NumberStyles.Currency, null);
}

Private Sub BindTextBoxControl()
   Dim myDataSet As New DataSet()
   ' Insert code to populate the DataSet with tables, columns, and data.

   ' Creates a new Binding object. 
   Dim myBinding As New Binding("Text", myDataSet, _
   "customers.custToOrders.OrderAmount")
   
   ' Adds event delegates for the Parse and Format events.
   AddHandler myBinding.Parse, AddressOf CurrencyToDecimal
   AddHandler myBinding.Format, AddressOf DecimalToCurrency
     
   ' Adds the new Binding to the BindingsCollection.
   text1.DataBindings.Add(myBinding)
End Sub 
    
Private Sub DecimalToCurrency(sender As Object, _
   cevent As ConvertEventArgs)
   ' This method is the Format event handler. Whenever the
   ' control displays a new value, the value is converted from
   ' its native Decimal type to a string. The ToString method
   ' then formats the value as a Currency, by using the
   ' formatting character "c". 
   cevent.Value = CDec(cevent.Value).ToString("c")
End Sub 
    
Private Sub CurrencyToDecimal(sender As Object, _
cevent As ConvertEventArgs)
   ' This method is the Parse event handler. The Parse event
   ' occurs whenever the displayed value changes. The static
   ' Parse method of the Decimal structure converts the 
   ' string back to its native Decimal type. 
   cevent.Value = Decimal.Parse(cevent.Value.ToString(), _
   NumberStyles.Currency, nothing)
   End Sub 

Commenti

L'data binding semplice viene eseguita aggiungendo Binding oggetti a un BindingsCollectionoggetto.Simple data binding is accomplished by adding Binding objects to a BindingsCollection. Qualsiasi oggetto che eredita dalla Control classe può accedere all' BindingsCollection oggetto tramite la DataBindings proprietà.Any object that inherits from the Control class can access the BindingsCollection through the DataBindings property. Per un elenco dei controlli Windows che supportano data binding, vedere la Binding classe.For a list of Windows controls that support data binding, see the Binding class.

Proprietà

Count Count Count Count

Ottiene il numero totale di associazioni nella raccolta.Gets the total number of bindings in the collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

Ottiene un valore che indica se la raccolta è di sola lettura.Gets a value indicating whether the collection is read-only.

(Inherited from BaseCollection)
IsSynchronized IsSynchronized IsSynchronized IsSynchronized

Ottiene un valore che indica se l'accesso all'interfaccia ICollection è sincronizzato.Gets a value indicating whether access to the ICollection is synchronized.

(Inherited from BaseCollection)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Ottiene Binding in corrispondenza dell'indice specificato.Gets the Binding at the specified index.

List List List List

Ottiene le associazioni nell'insieme come oggetto.Gets the bindings in the collection as an object.

SyncRoot SyncRoot SyncRoot SyncRoot

Ottiene un oggetto che può essere usato per sincronizzare l'accesso a BaseCollection.Gets an object that can be used to synchronize access to the BaseCollection.

(Inherited from BaseCollection)

Metodi

Add(Binding) Add(Binding) Add(Binding) Add(Binding)

Aggiunge l'associazione specificata all'insieme.Adds the specified binding to the collection.

AddCore(Binding) AddCore(Binding) AddCore(Binding) AddCore(Binding)

Aggiunge un oggetto Binding alla raccolta.Adds a Binding to the collection.

Clear() Clear() Clear() Clear()

Cancella la raccolta di oggetti di binding.Clears the collection of binding objects.

ClearCore() ClearCore() ClearCore() ClearCore()

Cancella la raccolta di membri.Clears the collection of any members.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

Copia tutti gli elementi dell'oggetto Array unidimensionale corrente nell'oggetto Array unidimensionale specificato a partire dall'indice Array di destinazione indicato.Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index.

(Inherited from BaseCollection)
CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Consente di creare un oggetto che contiene tutte le informazioni rilevanti necessarie per la generazione del proxy utilizzato per effettuare la comunicazione con un oggetto remoto.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Ottiene l'oggetto che consente di scorrere i membri dell'insieme.Gets the object that enables iterating through the members of the collection.

(Inherited from BaseCollection)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Funge da funzione hash predefinita.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Consente di recuperare l'oggetto servizio di durata corrente per controllare i criteri di durata per l'istanza.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Ottiene un oggetto servizio di durata per controllare i criteri di durata per questa istanza.Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Crea una copia dei riferimenti dell'oggetto MarshalByRefObject corrente.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs)

Genera l'evento CollectionChanged.Raises the CollectionChanged event.

OnCollectionChanging(CollectionChangeEventArgs) OnCollectionChanging(CollectionChangeEventArgs) OnCollectionChanging(CollectionChangeEventArgs) OnCollectionChanging(CollectionChangeEventArgs)

Genera l'evento CollectionChanging.Raises the CollectionChanging event.

Remove(Binding) Remove(Binding) Remove(Binding) Remove(Binding)

Elimina dall'insieme l'associazione specificata.Deletes the specified binding from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Elimina l'associazione dall'insieme in corrispondenza dell'indice specificato.Deletes the binding from the collection at the specified index.

RemoveCore(Binding) RemoveCore(Binding) RemoveCore(Binding) RemoveCore(Binding)

Rimuove l'oggetto Binding specificato dalla raccolta.Removes the specified Binding from the collection.

ShouldSerializeMyAll() ShouldSerializeMyAll() ShouldSerializeMyAll() ShouldSerializeMyAll()

Ottiene un valore che indica se è necessario serializzare l'insieme.Gets a value that indicates whether the collection should be serialized.

ToString() ToString() ToString() ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.Returns a string that represents the current object.

(Inherited from Object)

Eventi

CollectionChanged CollectionChanged CollectionChanged CollectionChanged

Si verifica in seguito alla modifica della raccolta.Occurs when the collection has changed.

CollectionChanging CollectionChanging CollectionChanging CollectionChanging

Si verifica quando la raccolta sta per essere modificata.Occurs when the collection is about to change.

Metodi di estensione

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

Esegue il cast degli elementi di un oggetto IEnumerable nel tipo specificato.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

Filtra gli elementi di un oggetto IEnumerable in base a un tipo specificato.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

Consente la parallelizzazione di una query.Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

Converte un oggetto IEnumerable in un oggetto IQueryable.Converts an IEnumerable to an IQueryable.

Si applica a

Vedi anche