ControlBindingsCollection Class
Represents the collection of data bindings for a control.
System::MarshalByRefObject
System.Windows.Forms::BaseCollection
System.Windows.Forms::BindingsCollection
System.Windows.Forms::ControlBindingsCollection
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The ControlBindingsCollection type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | ControlBindingsCollection | Initializes a new instance of the ControlBindingsCollection class with the specified bindable control. |
| Name | Description | |
|---|---|---|
![]() | BindableComponent | Gets the IBindableComponent the binding collection belongs to. |
![]() | Control | Gets the control that the collection belongs to. |
![]() | Count | Gets the total number of bindings in the collection. (Inherited from BindingsCollection.) |
![]() | DefaultDataSourceUpdateMode | Gets or sets the default DataSourceUpdateMode for a Binding in the collection. |
![]() | IsReadOnly | Gets a value indicating whether the collection is read-only. (Inherited from BaseCollection.) |
![]() | IsSynchronized | Gets a value indicating whether access to the ICollection is synchronized. (Inherited from BaseCollection.) |
![]() | Item[Int32] | Gets the Binding at the specified index. (Inherited from BindingsCollection.) |
![]() | Item[String] | Gets the Binding specified by the control's property name. |
![]() | List | Infrastructure. Gets the bindings in the collection as an object. (Inherited from BindingsCollection.) |
![]() | SyncRoot | Gets an object that can be used to synchronize access to the BaseCollection. (Inherited from BaseCollection.) |
| Name | Description | |
|---|---|---|
![]() | Add(Binding) | Adds the specified Binding to the collection. |
![]() | Add(String, Object, String) | Creates a Binding using the specified control property name, data source, and data member, and adds it to the collection. |
![]() | 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. |
![]() | 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. |
![]() | 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. |
![]() | 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. |
![]() | 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. |
![]() | AddCore | Adds a binding to the collection. (Overrides BindingsCollection::AddCore(Binding).) |
![]() | Clear | Clears the collection of any bindings. |
![]() | ClearCore | Infrastructure. Clears the bindings in the collection. (Overrides BindingsCollection::ClearCore().) |
![]() | 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.) |
![]() | 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.) |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetEnumerator | Gets the object that enables iterating through the members of the collection. (Inherited from BaseCollection.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() | OnCollectionChanged | Raises the CollectionChanged event. (Inherited from BindingsCollection.) |
![]() | OnCollectionChanging | Raises the CollectionChanging event. (Inherited from BindingsCollection.) |
![]() | Remove | Deletes the specified Binding from the collection. |
![]() | RemoveAt | Deletes the Binding at the specified index. |
![]() | RemoveCore | Infrastructure. Removes the specified binding from the collection. (Overrides BindingsCollection::RemoveCore(Binding).) |
![]() | ShouldSerializeMyAll | Gets a value that indicates whether the collection should be serialized. (Inherited from BindingsCollection.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() | CollectionChanged | Occurs when the collection has changed. (Inherited from BindingsCollection.) |
![]() | CollectionChanging | Occurs when the collection is about to change. (Inherited from BindingsCollection.) |
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( gcnew Binding( "Text",ds,"customers.custName" ) ); textBox2->DataBindings->Add( gcnew 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( gcnew 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 = gcnew Binding( "Text",ds,"customers.custToOrders.OrderAmount" ); b->Parse += gcnew ConvertEventHandler( this, &Form1::CurrencyStringToDecimal ); b->Format += gcnew ConvertEventHandler( this, &Form1::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() ); // 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() ); 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"]; }
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.
