BindingsCollection Class

Definition

Représente une collection d'objets Binding d'un contrôle.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
Inheritance
Derived

Examples

L’exemple suivant lie la propriété Text d’un contrôle TextBox à un champ d’une base de données.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 

Remarks

La liaison de données simple s’effectue en ajoutant des objets Binding à un BindingsCollection.Simple data binding is accomplished by adding Binding objects to a BindingsCollection. Tout objet qui hérite de la classe Control peut accéder au BindingsCollection via la propriété DataBindings.Any object that inherits from the Control class can access the BindingsCollection through the DataBindings property. Pour obtenir la liste des contrôles Windows qui prennent en charge la liaison de données, consultez la classe Binding.For a list of Windows controls that support data binding, see the Binding class.

Properties

Count

Obtient le nombre total de liaisons dans la collection.Gets the total number of bindings in the collection.

IsReadOnly

Obtient une valeur indiquant si la collection est en lecture seule.Gets a value indicating whether the collection is read-only.

(Inherited from BaseCollection)
IsSynchronized

Obtient une valeur indiquant si l'accès à ICollection est synchronisé.Gets a value indicating whether access to the ICollection is synchronized.

(Inherited from BaseCollection)
Item[Int32]

Obtient l'objet Binding à l'index spécifié.Gets the Binding at the specified index.

List

Obtient les liaisons de la collection en tant qu’objet.Gets the bindings in the collection as an object.

SyncRoot

Obtient un objet qui peut être utilisé pour synchroniser l’accès à BaseCollection.Gets an object that can be used to synchronize access to the BaseCollection.

(Inherited from BaseCollection)

Methods

Add(Binding)

Ajoute la liaison spécifiée à la collection.Adds the specified binding to the collection.

AddCore(Binding)

Ajoute un Binding à la collection.Adds a Binding to the collection.

Clear()

Efface la collection des objets de liaison.Clears the collection of binding objects.

ClearCore()

Efface la collection des membres.Clears the collection of any members.

CopyTo(Array, Int32)

Copie tous les éléments du Array unidimensionnel en cours dans le Array unidimensionnel spécifié en commençant à l'index Array de destination spécifié.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)

Crée un objet contenant toutes les informations appropriées requises pour générer un proxy permettant de communiquer avec un objet distant.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)

Détermine si l'objet spécifié est identique à l'objet actuel.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

Obtient l'objet qui permet l'itération au sein des membres de la collection.Gets the object that enables iterating through the members of the collection.

(Inherited from BaseCollection)
GetHashCode()

Fait office de fonction de hachage par défaut.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()

Récupère l'objet de service de durée de vie en cours qui contrôle la stratégie de durée de vie de cette instance.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType()

Obtient le Type de l'instance actuelle.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()

Obtient un objet de service de durée de vie pour contrôler la stratégie de durée de vie de cette instance.Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

Crée une copie superficielle du Object actuel.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Crée une copie superficielle de l'objet MarshalByRefObject actuel.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

Déclenche l'événement CollectionChanged.Raises the CollectionChanged event.

OnCollectionChanging(CollectionChangeEventArgs)

Déclenche l'événement CollectionChanging.Raises the CollectionChanging event.

Remove(Binding)

Supprime la liaison spécifiée de la collection.Deletes the specified binding from the collection.

RemoveAt(Int32)

Supprime la liaison de la collection à l’index spécifié.Deletes the binding from the collection at the specified index.

RemoveCore(Binding)

Supprime l’objet Binding spécifié de la collection.Removes the specified Binding from the collection.

ShouldSerializeMyAll()

Obtient une valeur indiquant si la collection doit être sérialisée.Gets a value that indicates whether the collection should be serialized.

ToString()

Retourne une chaîne qui représente l'objet actuel.Returns a string that represents the current object.

(Inherited from Object)

Events

CollectionChanged

Se produit lorsque la collection a été modifiée.Occurs when the collection has changed.

CollectionChanging

Se produit lorsque la collection est sur le point d'être modifiée.Occurs when the collection is about to change.

Extension Methods

Cast<TResult>(IEnumerable)

Effectue un cast des éléments d'un IEnumerable vers le type spécifié.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtre les éléments d'un IEnumerable en fonction du type spécifié.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Active la parallélisation d'une requête.Enables parallelization of a query.

AsQueryable(IEnumerable)

Convertit un IEnumerable en IQueryable.Converts an IEnumerable to an IQueryable.

Applies to

See also