This documentation is archived and is not being maintained.

Control.DataBindings Property

Gets the data bindings for the control.

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

Public ReadOnly Property DataBindings As ControlBindingsCollection
Dim instance As Control
Dim value As ControlBindingsCollection

value = instance.DataBindings

/** @property */
public final ControlBindingsCollection get_DataBindings ()

public final function get DataBindings () : ControlBindingsCollection

Not applicable.

Property Value

A ControlBindingsCollection that contains the Binding objects for the control.

Use the DataBindings property to access the ControlBindingsCollection. By adding Binding objects to the collection, you can bind any property of a control to the property of an object.

The following code example adds Binding objects to the ControlBindingsCollection of five controls: four TextBox controls and a DateTimePicker control. The ControlBindingsCollection is accessed through the DataBindings property of the Control class.

Protected Sub 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 specified by a navigation 
    ' path in the form : 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 specified by a 
    ' navigation path in the form: 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. 
    Dim b As New Binding("Text", ds, "customers.custToOrders.OrderAmount")
    AddHandler b.Parse, AddressOf CurrencyStringToDecimal
    AddHandler b.Format, AddressOf DecimalToCurrencyString
    ' Bind the fourth TextBox to the Value of the 
    ' DateTimePicker control. This demonstrates how one control
    ' can be bound to another.
    textBox4.DataBindings.Add("Text", DateTimePicker1, "Value")
    Dim bmText As BindingManagerBase = Me.BindingContext(DateTimePicker1)
    ' Print the Type of the BindingManagerBase, which is 
    ' a PropertyManager because the data source
    ' returns only a single property value. 
    ' Print the count of managed objects, which is 1.
    ' Get the BindingManagerBase for the Customers table. 
    bmCustomers = Me.BindingContext(ds, "Customers")
    ' Print the Type and count of the BindingManagerBase.
    ' Because the data source inherits from IBindingList,
    ' it is a RelatedCurrencyManager (derived from CurrencyManager). 
    ' Get the BindingManagerBase for the Orders of the current
    ' customer using a navigation path: TableName.RelationName. 
    bmOrders = Me.BindingContext(ds, "customers.CustToOrders")
End Sub    

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0