This topic has not yet been rated - Rate this topic

BindingsCollection Class

Represents a collection of Binding objects 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)
public class BindingsCollection : BaseCollection

The BindingsCollection type exposes the following members.

  Name Description
Public property Count Gets the total number of bindings in the collection. (Overrides BaseCollection.Count.)
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 Gets the Binding at the specified index.
Protected property List Infrastructure. Gets the bindings in the collection as an object. (Overrides BaseCollection.List.)
Public property SyncRoot Gets an object that can be used to synchronize access to the BaseCollection. (Inherited from BaseCollection.)
Top
  Name Description
Protected method Add Adds the specified binding to the collection.
Protected method AddCore Infrastructure. Adds a Binding to the collection.
Protected method Clear Clears the collection of binding objects.
Protected method ClearCore Infrastructure. Clears the collection of any members.
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.
Protected method OnCollectionChanging Raises the CollectionChanging event.
Protected method Remove Deletes the specified binding from the collection.
Protected method RemoveAt Deletes the binding from the collection at the specified index.
Protected method RemoveCore Infrastructure. Removes the specified Binding from the collection.
Protected method ShouldSerializeMyAll Gets a value that indicates whether the collection should be serialized.
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.
Public event CollectionChanging Occurs when the collection is about to change.
Top

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

The following example binds the Text property of a TextBox control to a field in a database.


private void BindTextBoxControl()
{
   DataSet myDataSet = new DataSet();
   /* Insert code to populate the DataSet with tables, 
   columns, and data. */

   // Creates a new Binding object. 
   Binding myBinding = new Binding
   ("Text", myDataSet, "customers.custToOrders.OrderAmount");

   // Adds event delegates for the Parse and Format events.
   myBinding.Parse += new ConvertEventHandler(CurrencyToDecimal);
   myBinding.Format += new ConvertEventHandler(DecimalToCurrency);

   // Adds the new Binding to the BindingsCollection.
   text1.DataBindings.Add(myBinding);
}

private void DecimalToCurrency(object sender, 
   ConvertEventArgs cevent)
{
   /* This method is the Format event handler. Whenever the 
   control displays a new value, the value is converted from 
   its native Decimal type to a string. The ToString method 
   then formats the value as a Currency, by using the 
   formatting character "c". */
   cevent.Value = ((decimal) cevent.Value).ToString("c");
}

private void CurrencyToDecimal(object sender, 
   ConvertEventArgs cevent)
{   
   /* This method is the Parse event handler. The Parse event 
   occurs whenever the displayed value changes. The static 
   Parse method of the Decimal structure converts the 
   string back to its native Decimal type. */
   cevent.Value = Decimal.Parse(cevent.Value.ToString(),
   NumberStyles.Currency, null);
}



.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