Export (0) Print
Expand All

ControlBindingsCollection Class

Represents the collection of data bindings for a control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[TypeConverterAttribute("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : BindingsCollection

The ControlBindingsCollection type exposes the following members.

  NameDescription
Public methodControlBindingsCollectionInitializes a new instance of the ControlBindingsCollection class with the specified bindable control.
Top

  NameDescription
Public propertyBindableComponentGets the IBindableComponent the binding collection belongs to.
Public propertyControlGets the control that the collection belongs to.
Public propertyCountGets the total number of bindings in the collection. (Inherited from BindingsCollection.)
Public propertyDefaultDataSourceUpdateModeGets or sets the default DataSourceUpdateMode for a Binding in the collection.
Public propertyIsReadOnlyGets a value indicating whether the collection is read-only. (Inherited from BaseCollection.)
Public propertyIsSynchronizedGets a value indicating whether access to the ICollection is synchronized. (Inherited from BaseCollection.)
Public propertyItem[Int32]Gets the Binding at the specified index. (Inherited from BindingsCollection.)
Public propertyItem[String]Gets the Binding specified by the control's property name.
Protected propertyListInfrastructure. Gets the bindings in the collection as an object. (Inherited from BindingsCollection.)
Public propertySyncRootGets an object that can be used to synchronize access to the BaseCollection. (Inherited from BaseCollection.)
Top

  NameDescription
Public methodAdd(Binding)Adds the specified Binding to the collection.
Public methodAdd(String, Object, String)Creates a Binding using the specified control property name, data source, and data member, and adds it to the collection.
Public methodAdd(String, Object, String, Boolean)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.
Public methodAdd(String, Object, String, Boolean, DataSourceUpdateMode)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.
Public methodAdd(String, Object, String, Boolean, DataSourceUpdateMode, Object)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.
Public methodAdd(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)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.
Public methodAdd(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)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.
Protected methodAddCoreAdds a binding to the collection. (Overrides BindingsCollection.AddCore(Binding).)
Public methodClearClears the collection of any bindings.
Protected methodClearCoreInfrastructure. Clears the bindings in the collection. (Overrides BindingsCollection.ClearCore().)
Public methodCopyToCopies 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.)
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetEnumeratorGets the object that enables iterating through the members of the collection. (Inherited from BaseCollection.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodOnCollectionChangedRaises the CollectionChanged event. (Inherited from BindingsCollection.)
Protected methodOnCollectionChangingRaises the CollectionChanging event. (Inherited from BindingsCollection.)
Public methodRemoveDeletes the specified Binding from the collection.
Public methodRemoveAtDeletes the Binding at the specified index.
Protected methodRemoveCoreInfrastructure. Removes the specified binding from the collection. (Overrides BindingsCollection.RemoveCore(Binding).)
Protected methodShouldSerializeMyAllGets a value that indicates whether the collection should be serialized. (Inherited from BindingsCollection.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventCollectionChangedOccurs when the collection has changed. (Inherited from BindingsCollection.)
Public eventCollectionChangingOccurs when the collection is about to change. (Inherited from BindingsCollection.)
Top

Simple data binding is accomplished by adding Binding objects to a ControlBindingsCollection. Any object that inherits from the Control class can access the ControlBindingsCollection through the DataBindings property. For a list of Windows controls that support data binding, see the Binding class.

The ControlBindingsCollection contains standard collection methods such as Add, Clear, and Remove.

To get the control that the ControlBindingsCollection belongs to, use the Control property.

The following code example adds Binding objects to a ControlBindingsCollection of five controls: four TextBox controls and a DateTimePicker 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(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"];
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft