Export (0) Print
Expand All

BindingsCollection Class

Represents a collection of Binding objects for a control.

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

public class BindingsCollection : BaseCollection

The BindingsCollection type exposes the following members.

  NameDescription
Public propertyCountGets the total number of bindings in the collection. (Overrides BaseCollection.Count.)
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 propertyItemGets the Binding at the specified index.
Protected propertyListInfrastructure. Gets the bindings in the collection as an object. (Overrides BaseCollection.List.)
Public propertySyncRootGets an object that can be used to synchronize access to the BaseCollection. (Inherited from BaseCollection.)
Top

  NameDescription
Protected methodAddAdds the specified binding to the collection.
Protected methodAddCoreInfrastructure. Adds a Binding to the collection.
Protected methodClearClears the collection of binding objects.
Protected methodClearCoreInfrastructure. Clears the collection of any members.
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 a hash function for a particular type. (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.
Protected methodOnCollectionChangingRaises the CollectionChanging event.
Protected methodRemoveDeletes the specified binding from the collection.
Protected methodRemoveAtDeletes the binding from the collection at the specified index.
Protected methodRemoveCoreInfrastructure. Removes the specified Binding from the collection.
Protected methodShouldSerializeMyAllGets a value that indicates whether the collection should be serialized.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public eventCollectionChangedOccurs when the collection has changed.
Public eventCollectionChangingOccurs 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.

Community Additions

ADD
Show:
© 2014 Microsoft