ControlBindingsCollection Clase
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Representa la colección de enlaces de datos para un control .
public ref class ControlBindingsCollection : System::Windows::Forms::BindingsCollection
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
[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
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
inherit BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
inherit BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
inherit BindingsCollection
Public Class ControlBindingsCollection
Inherits BindingsCollection
- Herencia
- Atributos
Ejemplos
En el ejemplo de código siguiente se agregan Binding objetos a un ControlBindingsCollection de cinco controles: cuatro TextBox controles y un DateTimePicker control . ControlBindingsCollection Se obtiene acceso a a través de la DataBindings propiedad de la Control clase .
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 .ControlBindingsCollection Cualquier objeto que herede de la Control clase puede tener acceso a ControlBindingsCollection a través de la DataBindings propiedad . Para obtener una lista de controles de Windows que admiten el enlace de datos, consulte la Binding clase .
ControlBindingsCollection contiene métodos de colección estándar como Add, Cleary Remove.
Para obtener el control al que ControlBindingsCollection pertenece, use la Control propiedad .
Constructores
| Nombre | Description |
|---|---|
| ControlBindingsCollection(IBindableComponent) |
Inicializa una nueva instancia de la ControlBindingsCollection clase con el control enlazable especificado. |
Propiedades
| Nombre | Description |
|---|---|
| BindableComponent |
Obtiene la IBindableComponent colección de enlaces a la que pertenece. |
| Control |
Obtiene el control al que pertenece la colección. |
| Count |
Obtiene el número total de enlaces de la colección. (Heredado de BindingsCollection) |
| DefaultDataSourceUpdateMode |
Obtiene o establece el valor predeterminado DataSourceUpdateMode de en Binding la colección . |
| IsReadOnly |
Obtiene un valor que indica si la colección es de solo lectura. (Heredado de BaseCollection) |
| IsSynchronized |
Obtiene un valor que indica si se sincroniza el acceso a .ICollection (Heredado de BaseCollection) |
| Item[Int32] |
Obtiene en Binding el índice especificado. (Heredado de BindingsCollection) |
| Item[String] |
Obtiene el Binding especificado por el nombre de propiedad del control. |
| List |
Obtiene los enlaces de la colección como un objeto . (Heredado de BindingsCollection) |
| SyncRoot |
Obtiene un objeto que se puede usar para sincronizar el acceso a la BaseCollection. (Heredado de BaseCollection) |
Métodos
| Nombre | Description |
|---|---|
| Add(Binding) |
Agrega el objeto especificado Binding a la colección. |
| 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 al origen de datos según la configuración de actualización especificada, estableciendo la propiedad en el valor especificado cuando DBNull se devuelve desde el origen de datos, estableciendo el proveedor de formato especificado, y agregar el enlace a la colección. |
| 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 al origen de datos en función de la configuración de actualización especificada, estableciendo la propiedad en el valor especificado cuando DBNull se devuelve desde el origen de datos y agregando el enlace a la colección. |
| 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 al origen de datos en función de la configuración de actualización especificada, estableciendo la propiedad en el valor especificado cuando DBNull se devuelve desde el origen de datos y agregando el enlace a la colección. |
| 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 al origen de datos en función de la configuración de actualización especificada y agregando el enlace a la colección. |
| Add(String, Object, String, Boolean) |
Crea un enlace con el nombre de la propiedad de control, el origen de datos, el miembro de datos y la información sobre si el formato está habilitado y agrega el enlace a la colección. |
| Add(String, Object, String) |
Crea un Binding con el nombre de propiedad de control, el origen de datos y el miembro de datos especificados, y lo agrega a la colección. |
| AddCore(Binding) |
Agrega un enlace a la colección. |
| Clear() |
Borra la colección de cualquier enlace. |
| ClearCore() |
Borra los enlaces de la colección. |
| CopyTo(Array, Int32) |
Copia todos los elementos de la unidimensional actual en la unidimensional ArrayArray especificada a partir del índice de destino Array especificado. (Heredado de BaseCollection) |
| CreateObjRef(Type) |
Crea un objeto que contiene toda la información pertinente necesaria para generar un proxy usado para comunicarse con un objeto remoto. (Heredado de MarshalByRefObject) |
| Equals(Object) |
Determina si el objeto especificado es igual al objeto actual. (Heredado de Object) |
| GetEnumerator() |
Obtiene el objeto que permite recorrer en iteración los miembros de la colección. (Heredado de BaseCollection) |
| GetHashCode() |
Actúa como función hash predeterminada. (Heredado de Object) |
| GetLifetimeService() |
Obsoletos.
Recupera el objeto de servicio de duración actual que controla la directiva de duración de esta instancia. (Heredado de MarshalByRefObject) |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| InitializeLifetimeService() |
Obsoletos.
Obtiene un objeto de servicio de duración para controlar la directiva de duración de esta instancia. (Heredado de MarshalByRefObject) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| MemberwiseClone(Boolean) |
Crea una copia superficial del objeto actual MarshalByRefObject . (Heredado de MarshalByRefObject) |
| OnCollectionChanged(CollectionChangeEventArgs) |
Genera el evento CollectionChanged. (Heredado de BindingsCollection) |
| OnCollectionChanging(CollectionChangeEventArgs) |
Genera el evento CollectionChanging. (Heredado de BindingsCollection) |
| Remove(Binding) |
Elimina el especificado Binding de la colección. |
| RemoveAt(Int32) |
Elimina en Binding el índice especificado. |
| RemoveCore(Binding) |
Quita el enlace especificado de la colección. |
| ShouldSerializeMyAll() |
Obtiene un valor que indica si se debe serializar la colección. (Heredado de BindingsCollection) |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |
Eventos
| Nombre | Description |
|---|---|
| CollectionChanged |
Se produce cuando la colección ha cambiado. (Heredado de BindingsCollection) |
| CollectionChanging |
Se produce cuando la colección está a punto de cambiar. (Heredado de BindingsCollection) |
Métodos de extensión
| Nombre | Description |
|---|---|
| AsParallel(IEnumerable) |
Habilita la paralelización de una consulta. |
| AsQueryable(IEnumerable) |
Convierte un IEnumerable en un IQueryable. |
| Cast<TResult>(IEnumerable) |
Convierte los elementos de un IEnumerable al tipo especificado. |
| OfType<TResult>(IEnumerable) |
Filtra los elementos de un IEnumerable en función de un tipo especificado. |