Control.BindingContext Propiedad

Definición

Obtiene o establece la plantilla BindingContext para el control.

C#
[System.ComponentModel.Browsable(false)]
public virtual System.Windows.Forms.BindingContext BindingContext { get; set; }
C#
[System.ComponentModel.Browsable(false)]
public virtual System.Windows.Forms.BindingContext? BindingContext { get; set; }

Valor de propiedad

BindingContext

BindingContext del control.

Implementaciones

Atributos

Ejemplos

En el ejemplo de código siguiente se crean cuatro Binding objetos para enlazar cinco controles, uno DateTimePicker y cuatro TextBox controles, a varios orígenes de datos. BindingContext A continuación, se usa para obtener para BindingManagerBase cada origen de datos.

C#
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 a navigation path in the form: 
      "TableName.ColumnName". */
   text1.DataBindings.Add(new Binding
   ("Text", ds, "customers.custName"));
   text2.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 string. */
   DateTimePicker1.DataBindings.Add(new 
   Binding("Value", ds, "customers.CustToOrders.OrderDate"));

   /* Add event delegates for the Parse and Format events to a 
      new 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);
   text3.DataBindings.Add(b);

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

   /* Get the BindingManagerBase for the Orders table using the 
      RelationName. */ 
   bmOrders = this.BindingContext[ds, "customers.CustToOrders"];

   /* Bind the fourth TextBox control's Text property to the
   third control's Text property. */
   text4.DataBindings.Add("Text", text3, "Text");
}

Comentarios

de BindingContext Control se usa para devolver un único BindingManagerBase para todos los controles enlazados a datos contenidos en .Control BindingManagerBase mantiene sincronizados todos los controles enlazados al mismo origen de datos. Por ejemplo, al establecer la Position propiedad de especifica BindingManagerBase el elemento de la lista subyacente a la que apuntan todos los controles enlazados a datos.

Para obtener más información sobre cómo crear un nuevo BindingContext y asignarlo a la BindingContext propiedad , vea .BindingContext

Notas a los desarrolladores de herederos

Al invalidar la BindingContext propiedad en una clase derivada, utilice la propiedad de BindingContext la clase base para extender la implementación base. De lo contrario, debe proporcionar toda la implementación. No es necesario invalidar los get descriptores de acceso y set de la BindingContext propiedad; solo se puede invalidar uno si es necesario.

Se aplica a

Producto Versiones
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

Consulte también