ControlBindingsCollection Clase

Definición

Representa la colección de enlaces de datos de un control.Represents the collection of data bindings for a control.

public ref class ControlBindingsCollection : System::Windows::Forms::BindingsCollection
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
type ControlBindingsCollection = class
    inherit BindingsCollection
Public Class ControlBindingsCollection
Inherits BindingsCollection
Herencia
Atributos

Ejemplos

En el ejemplo de código siguiente se agregan objetos Binding a un ControlBindingsCollection de cinco controles: cuatro controles TextBox y un control DateTimePicker.The following code example adds Binding objects to a ControlBindingsCollection of five controls: four TextBox controls and a DateTimePicker control. Se obtiene acceso a ControlBindingsCollection mediante la propiedad DataBindings de la clase Control.The ControlBindingsCollection is accessed through the DataBindings property of the Control class.

protected:
   void BindControls()
   {
      /* Create two Binding objects for the first two TextBox 
         controls. The data-bound property for both controls 
         is the Text property. The data source is a DataSet 
         (ds). The data member is the navigation path: 
         TableName.ColumnName. */
      textBox1->DataBindings->Add( gcnew Binding(
         "Text",ds,"customers.custName" ) );
      textBox2->DataBindings->Add( gcnew Binding(
         "Text",ds,"customers.custID" ) );
      
      /* Bind the DateTimePicker control by adding a new Binding. 
         The data member of the DateTimePicker is a navigation path:
         TableName.RelationName.ColumnName. */
      DateTimePicker1->DataBindings->Add( gcnew Binding(
         "Value",ds,"customers.CustToOrders.OrderDate" ) );
      
      /* Create a new Binding using the DataSet and a 
         navigation path(TableName.RelationName.ColumnName).
         Add event delegates for the Parse and Format events to 
         the Binding object, and add the object to the third 
         TextBox control's BindingsCollection. The delegates 
         must be added before adding the Binding to the 
         collection; otherwise, no formatting occurs until 
         the Current object of the BindingManagerBase for 
         the data source changes. */
      Binding^ b = gcnew Binding(
         "Text",ds,"customers.custToOrders.OrderAmount" );
      b->Parse += gcnew ConvertEventHandler(
         this, &Form1::CurrencyStringToDecimal );
      b->Format += gcnew ConvertEventHandler(
         this, &Form1::DecimalToCurrencyString );
      textBox3->DataBindings->Add( b );
      
      /*Bind the fourth TextBox to the Value of the 
         DateTimePicker control. This demonstates how one control
         can be data-bound to another.*/
      textBox4->DataBindings->Add( "Text", DateTimePicker1, "Value" );
      
      // Get the BindingManagerBase for the textBox4 Binding.
      BindingManagerBase^ bmText = this->BindingContext[
         DateTimePicker1 ];
      
      /* Print the Type of the BindingManagerBase, which is 
         a PropertyManager because the data source
         returns only a single property value. */
      Console::WriteLine( bmText->GetType() );
      
      // Print the count of managed objects, which is one.
      Console::WriteLine( bmText->Count );
      
      // Get the BindingManagerBase for the Customers table. 
      bmCustomers = this->BindingContext[ds, "Customers"];
      
      /* Print the Type and count of the BindingManagerBase.
         Because the data source inherits from IBindingList,
         it is a RelatedCurrencyManager (a derived class of
         CurrencyManager). */
      Console::WriteLine( bmCustomers->GetType() );
      Console::WriteLine( bmCustomers->Count );
      
      /* Get the BindingManagerBase for the Orders of the current
         customer using a navigation path: TableName.RelationName. */
      bmOrders = this->BindingContext[ds, "customers.CustToOrders"];
   }
protected void BindControls()
{
   /* Create two Binding objects for the first two TextBox 
   controls. The data-bound property for both controls 
   is the Text property. The data source is a DataSet 
   (ds). The data member is the navigation path: 
   TableName.ColumnName. */
   textBox1.DataBindings.Add(new Binding
   ("Text", ds, "customers.custName"));
   textBox2.DataBindings.Add(new Binding
   ("Text", ds, "customers.custID"));
      
   /* Bind the DateTimePicker control by adding a new Binding. 
   The data member of the DateTimePicker is a navigation path:
   TableName.RelationName.ColumnName. */
   DateTimePicker1.DataBindings.Add(new 
   Binding("Value", ds, "customers.CustToOrders.OrderDate"));

   /* Create a new Binding using the DataSet and a 
   navigation path(TableName.RelationName.ColumnName).
   Add event delegates for the Parse and Format events to 
   the Binding object, and add the object to the third 
   TextBox control's BindingsCollection. The delegates 
   must be added before adding the Binding to the 
   collection; otherwise, no formatting occurs until 
   the Current object of the BindingManagerBase for 
   the data source changes. */
   Binding b = new Binding
   ("Text", ds, "customers.custToOrders.OrderAmount");
   b.Parse+=new ConvertEventHandler(CurrencyStringToDecimal);
   b.Format+=new ConvertEventHandler(DecimalToCurrencyString);
   textBox3.DataBindings.Add(b);

   /*Bind the fourth TextBox to the Value of the 
   DateTimePicker control. This demonstates how one control
   can be data-bound to another.*/
   textBox4.DataBindings.Add("Text", DateTimePicker1,"Value");

   // Get the BindingManagerBase for the textBox4 Binding.
   BindingManagerBase bmText = this.BindingContext
   [DateTimePicker1];

   /* Print the Type of the BindingManagerBase, which is 
   a PropertyManager because the data source
   returns only a single property value. */
   Console.WriteLine(bmText.GetType().ToString());

   // Print the count of managed objects, which is one.
   Console.WriteLine(bmText.Count);

   // Get the BindingManagerBase for the Customers table. 
   bmCustomers = this.BindingContext [ds, "Customers"];

   /* Print the Type and count of the BindingManagerBase.
   Because the data source inherits from IBindingList,
   it is a RelatedCurrencyManager (a derived class of
   CurrencyManager). */
   Console.WriteLine(bmCustomers.GetType().ToString());
   Console.WriteLine(bmCustomers.Count);
   
   /* Get the BindingManagerBase for the Orders of the current
   customer using a navigation path: TableName.RelationName. */ 
   bmOrders = this.BindingContext[ds, "customers.CustToOrders"];
}
Protected Sub BindControls()
    ' Create two Binding objects for the first two TextBox 
    ' controls. The data-bound property for both controls 
    ' is the Text property. The data source is a DataSet 
    ' (ds). The data member is the navigation path: 
    ' TableName.ColumnName. 
    textBox1.DataBindings.Add _
       (New Binding("Text", ds, "customers.custName"))
    textBox2.DataBindings.Add _
       (New Binding("Text", ds, "customers.custID"))
    
    ' Bind the DateTimePicker control by adding a new Binding. 
    ' The data member of the DateTimePicker is a navigation path:
    ' TableName.RelationName.ColumnName. 
    DateTimePicker1.DataBindings.Add _
       (New Binding("Value", ds, "customers.CustToOrders.OrderDate"))
    
    ' Create a new Binding using the DataSet and a 
    ' navigation path(TableName.RelationName.ColumnName).
    ' Add event delegates for the Parse and Format events to 
    ' the Binding object, and add the object to the third 
    ' TextBox control's BindingsCollection. The delegates 
    ' must be added before adding the Binding to the 
    ' collection; otherwise, no formatting occurs until 
    ' the Current object of the BindingManagerBase for 
    ' the data source changes. 
    Dim b As New Binding("Text", ds, "customers.custToOrders.OrderAmount")
    AddHandler b.Parse, AddressOf CurrencyStringToDecimal
    AddHandler b.Format, AddressOf DecimalToCurrencyString
    textBox3.DataBindings.Add(b)
    
    ' Bind the fourth TextBox to the Value of the 
    ' DateTimePicker control. This demonstates how one control
    ' can be data-bound to another.
    textBox4.DataBindings.Add("Text", DateTimePicker1, "Value")
    
    ' Get the BindingManagerBase for the textBox4 Binding.
    Dim bmText As BindingManagerBase = Me.BindingContext(DateTimePicker1)
    
    ' Print the Type of the BindingManagerBase, which is 
    ' a PropertyManager because the data source
    ' returns only a single property value. 
    Console.WriteLine(bmText.GetType().ToString())
    
    ' Print the count of managed objects, which is one.
    Console.WriteLine(bmText.Count)
    
    ' Get the BindingManagerBase for the Customers table. 
    bmCustomers = Me.BindingContext(ds, "Customers")
    
    ' Print the Type and count of the BindingManagerBase.
    ' Because the data source inherits from IBindingList,
    ' it is a RelatedCurrencyManager (a derived class of
    ' CurrencyManager). 
    Console.WriteLine(bmCustomers.GetType().ToString())
    Console.WriteLine(bmCustomers.Count)
    
    ' Get the BindingManagerBase for the Orders of the current
    ' customer using a navigation path: TableName.RelationName. 
    bmOrders = Me.BindingContext(ds, "customers.CustToOrders")
End Sub    

Comentarios

El enlace de datos simple se logra agregando Binding objetos a un ControlBindingsCollection.Simple data binding is accomplished by adding Binding objects to a ControlBindingsCollection. Cualquier objeto que herede de la clase Control puede tener acceso al ControlBindingsCollection a través de la propiedad DataBindings.Any object that inherits from the Control class can access the ControlBindingsCollection through the DataBindings property. Para obtener una lista de controles de Windows que admiten el enlace de datos, vea la clase Binding.For a list of Windows controls that support data binding, see the Binding class.

El ControlBindingsCollection contiene métodos de colección estándar como Add, Cleary Remove.The ControlBindingsCollection contains standard collection methods such as Add, Clear, and Remove.

Para obtener el control al que pertenece el ControlBindingsCollection, use la propiedad Control.To get the control that the ControlBindingsCollection belongs to, use the Control property.

Constructores

ControlBindingsCollection(IBindableComponent)

Inicializa una nueva instancia de la clase ControlBindingsCollection con el control especificado que se puede enlazar.Initializes a new instance of the ControlBindingsCollection class with the specified bindable control.

Propiedades

BindableComponent

Obtiene el elemento IBindableComponent al que pertenece la colección de enlaces.Gets the IBindableComponent the binding collection belongs to.

Control

Obtiene el control al que pertenece la colección.Gets the control that the collection belongs to.

Count

Obtiene el número total de enlaces de la colección.Gets the total number of bindings in the collection.

(Heredado de BindingsCollection)
DefaultDataSourceUpdateMode

Obtiene o establece el DataSourceUpdateMode predeterminado para un elemento Binding de la colección.Gets or sets the default DataSourceUpdateMode for a Binding in the collection.

IsReadOnly

Obtiene un valor que indica si la colección es de solo lectura.Gets a value indicating whether the collection is read-only.

(Heredado de BaseCollection)
IsSynchronized

Obtiene un valor que indica si el acceso a ICollection está sincronizado.Gets a value indicating whether access to the ICollection is synchronized.

(Heredado de BaseCollection)
Item[Int32]

Obtiene el objeto Binding en el índice especificado.Gets the Binding at the specified index.

(Heredado de BindingsCollection)
Item[String]

Obtiene el objeto Binding que especifica el nombre de propiedad del control.Gets the Binding specified by the control's property name.

List

Obtiene los enlaces de la colección como un objeto.Gets the bindings in the collection as an object.

(Heredado de BindingsCollection)
SyncRoot

Obtiene un objeto que se puede usar para sincronizar el acceso a BaseCollection.Gets an object that can be used to synchronize access to the BaseCollection.

(Heredado de BaseCollection)

Métodos

Add(Binding)

Agrega el Binding especificado a la colección.Adds the specified Binding to the collection.

Add(String, Object, String)

Crea un Binding usando el nombre de propiedad de control, el origen de datos y el miembro de datos especificados, y lo agrega a la colección.Creates a Binding using the specified control property name, data source, and data member, and adds it to the collection.

Add(String, Object, String, Boolean)

Crea un enlace con el nombre de propiedad, origen de datos, miembro de datos e información sobre el formato habilitado relativo al control especificado y agrega el enlace a la colección.Creates a binding with the specified control property name, data source, data member, and information about whether formatting is enabled, and adds the binding to the collection.

Add(String, Object, String, Boolean, DataSourceUpdateMode)

Crea un enlace que enlaza la propiedad de control especificada al miembro de datos especificado del origen de datos especificado, habilitando opcionalmente el formato, propagando valores a los orígenes de datos basados en la configuración de actualización especificada y agregando el enlace a la colección.Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting, propagating values to the data source based on the specified update setting, and adding the binding to the collection.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object)

Crea un enlace que enlaza la propiedad de control especificada al miembro de datos especificado del origen de datos especificado, habilitando opcionalmente el formato, propagando valores a los orígenes de datos basados en la configuración de actualización especificada, estableciendo la propiedad en el valor especificado cuando el origen de datos devuelve DBNull y agregando el enlace a la colección.Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting, propagating values to the data source based on the specified update setting, setting the property to the specified value when DBNull is returned from the data source, and adding the binding to the collection.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

Crea un enlace que enlaza la propiedad de control especificada al miembro de datos especificado del origen de datos especificado, habilitando opcionalmente el formato con la cadena de formato especificada, propagando valores a los orígenes de datos basados en la configuración de actualización especificada, estableciendo la propiedad en el valor especificado cuando el origen de datos devuelve DBNull y agregando el enlace a la colección.Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting with the specified format string, propagating values to the data source based on the specified update setting, setting the property to the specified value when DBNull is returned from the data source, and adding the binding to the collection.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)

Crea un enlace que enlaza la propiedad de control especificada al miembro de datos especificado del origen de datos especificado, habilitando opcionalmente el formato con la cadena de formato especificada, propagando valores a los orígenes de datos basados en la configuración de actualización especificada, estableciendo la propiedad en el valor especificado cuando el origen de datos devuelve DBNull, estableciendo el proveedor de formato especificado y agregando el enlace a la colección.Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting with the specified format string, propagating values to the data source based on the specified update setting, setting the property to the specified value when DBNull is returned from the data source, setting the specified format provider, and adding the binding to the collection.

AddCore(Binding)

Agrega un enlace a la colección.Adds a binding to the collection.

Clear()

Borra la colección de todos los enlaces.Clears the collection of any bindings.

ClearCore()

Borra los enlaces de la colección.Clears the bindings in the collection.

CopyTo(Array, Int32)

Copia todos los elementos del objeto Array unidimensional actual en el objeto Array unidimensional especificado, empezando en el índice especificado del objeto Array de destino.Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index.

(Heredado de BaseCollection)
CreateObjRef(Type)

Crea un objeto que contiene toda la información relevante necesaria para generar un proxy utilizado para comunicarse con un objeto remoto.Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Heredado de MarshalByRefObject)
Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Heredado de Object)
GetEnumerator()

Obtiene el objeto que permite iterar en los miembros de la colección.Gets the object that enables iterating through the members of the collection.

(Heredado de BaseCollection)
GetHashCode()

Sirve como función hash predeterminada.Serves as the default hash function.

(Heredado de Object)
GetLifetimeService()

Recupera el objeto de servicio de duración actual que controla la directiva de duración de esta instancia.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Heredado de MarshalByRefObject)
GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Heredado de Object)
InitializeLifetimeService()

Obtiene un objeto de servicio de duración para controlar la directiva de duración de esta instancia.Obtains a lifetime service object to control the lifetime policy for this instance.

(Heredado de MarshalByRefObject)
MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
MemberwiseClone(Boolean)

Crea una copia superficial del objeto MarshalByRefObject actual.Creates a shallow copy of the current MarshalByRefObject object.

(Heredado de MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

Genera el evento CollectionChanged.Raises the CollectionChanged event.

(Heredado de BindingsCollection)
OnCollectionChanging(CollectionChangeEventArgs)

Genera el evento CollectionChanging.Raises the CollectionChanging event.

(Heredado de BindingsCollection)
Remove(Binding)

Elimina el elemento Binding especificado de la colección.Deletes the specified Binding from the collection.

RemoveAt(Int32)

Elimina el elemento Binding en el índice especificado.Deletes the Binding at the specified index.

RemoveCore(Binding)

Quita el enlace especificado de la colección.Removes the specified binding from the collection.

ShouldSerializeMyAll()

Obtiene un valor que indica si la colección debe serializarse.Gets a value that indicates whether the collection should be serialized.

(Heredado de BindingsCollection)
ToString()

Devuelve un valor de tipo string que representa el objeto actual.Returns a string that represents the current object.

(Heredado de Object)

Eventos

CollectionChanged

Se produce cuando cambia la colección.Occurs when the collection has changed.

(Heredado de BindingsCollection)
CollectionChanging

Se produce cuando va a cambiar la colección.Occurs when the collection is about to change.

(Heredado de BindingsCollection)

Métodos de extensión

Cast<TResult>(IEnumerable)

Convierte los elementos de IEnumerable en el tipo especificado.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtra los elementos de IEnumerable en función de un tipo especificado.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Habilita la paralelización de una consulta.Enables parallelization of a query.

AsQueryable(IEnumerable)

Convierte una interfaz IEnumerable en IQueryable.Converts an IEnumerable to an IQueryable.

Se aplica a