This topic has not yet been rated - Rate this topic

ControlBindingsCollection Class

Represents the collection of data bindings for a control.

System.Object
  System.MarshalByRefObject
    System.Windows.Forms.BaseCollection
      System.Windows.Forms.BindingsCollection
        System.Windows.Forms.ControlBindingsCollection

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.

  Name Description
Public method ControlBindingsCollection Initializes a new instance of the ControlBindingsCollection class with the specified bindable control.
Top
  Name Description
Public property BindableComponent Gets the IBindableComponent the binding collection belongs to.
Public property Control Gets the control that the collection belongs to.
Public property Count Gets the total number of bindings in the collection. (Inherited from BindingsCollection.)
Public property DefaultDataSourceUpdateMode Gets or sets the default DataSourceUpdateMode for a Binding in the collection.
Public property IsReadOnly Gets a value indicating whether the collection is read-only. (Inherited from BaseCollection.)
Public property IsSynchronized Gets a value indicating whether access to the ICollection is synchronized. (Inherited from BaseCollection.)
Public property Item[Int32] Gets the Binding at the specified index. (Inherited from BindingsCollection.)
Public property Item[String] Gets the Binding specified by the control's property name.
Protected property List Infrastructure. Gets the bindings in the collection as an object. (Inherited from BindingsCollection.)
Public property SyncRoot Gets an object that can be used to synchronize access to the BaseCollection. (Inherited from BaseCollection.)
Top
  Name Description
Public method Add(Binding) Adds the specified Binding to the collection.
Public method Add(String, Object, String) Creates a Binding using the specified control property name, data source, and data member, and adds it to the collection.
Public method Add(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 method Add(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 method Add(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 method Add(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 method Add(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 method AddCore Adds a binding to the collection. (Overrides BindingsCollection.AddCore(Binding).)
Public method Clear Clears the collection of any bindings.
Protected method ClearCore Infrastructure. Clears the bindings in the collection. (Overrides BindingsCollection.ClearCore().)
Public method CopyTo Copies 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 method CreateObjRef Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumerator Gets the object that enables iterating through the members of the collection. (Inherited from BaseCollection.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetLifetimeService Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method InitializeLifetimeService Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected method MemberwiseClone() Creates a shallow copy of the current Object. (Inherited from Object.)
Protected method MemberwiseClone(Boolean) Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected method OnCollectionChanged Raises the CollectionChanged event. (Inherited from BindingsCollection.)
Protected method OnCollectionChanging Raises the CollectionChanging event. (Inherited from BindingsCollection.)
Public method Remove Deletes the specified Binding from the collection.
Public method RemoveAt Deletes the Binding at the specified index.
Protected method RemoveCore Infrastructure. Removes the specified binding from the collection. (Overrides BindingsCollection.RemoveCore(Binding).)
Protected method ShouldSerializeMyAll Gets a value that indicates whether the collection should be serialized. (Inherited from BindingsCollection.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
  Name Description
Public event CollectionChanged Occurs when the collection has changed. (Inherited from BindingsCollection.)
Public event CollectionChanging Occurs 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, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ