ControlBindingsCollection (Clase)
Actualización: noviembre 2007
Representa la colección de enlaces de datos de un control.
Ensamblado: System.Windows.Forms (en System.Windows.Forms.dll)
[TypeConverterAttribute("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] public class ControlBindingsCollection : BindingsCollection
/** @attribute TypeConverterAttribute("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") */
public class ControlBindingsCollection extends BindingsCollection
Un enlace de datos simple se consigue agregando objetos Binding a ControlBindingsCollection. Cualquier objeto que hereda de la clase Control puede tener acceso a ControlBindingsCollection mediante la propiedad DataBindings. Para obtener una lista de los controles de Windows que admiten enlaces de datos, vea la clase Binding.
ControlBindingsCollection contiene métodos de colección estándar, como Add, Clear y Remove.
Para obtener el control al que pertenece ControlBindingsCollection use la propiedad Control.
En el siguiente ejemplo de código se agregan objetos Binding a una ControlBindingsCollection de cinco controles: cuatro controles TextBox y un control DateTimePicker. Se obtiene acceso a ControlBindingsCollection mediante la propiedad DataBindings de la clase Control.
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"]; }
System.MarshalByRefObject
System.Windows.Forms.BaseCollection
System.Windows.Forms.BindingsCollection
System.Windows.Forms.ControlBindingsCollection
Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile para Smartphone, Windows Mobile para Pocket PC
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.