ControlBindingsCollection.Add Method (String, Object, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Creates a Binding using the specified control property name, data source, and data member, and adds it to the collection.

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

public Binding Add(
	string propertyName,
	object dataSource,
	string dataMember


Type: System.String

The name of the control property to bind.

Type: System.Object

An Object that represents the data source.

Type: System.String

The property or list to bind to.

Return Value

Type: System.Windows.Forms.Binding

The newly created Binding.

Exception Condition

The binding is null.


The propertyName is already data-bound.


The dataMember doesn't specify a valid member of the dataSource.

The DataSourceUpdateMode property of the Binding created by this overload of the Add method is set to the value of the DefaultDataSourceUpdateMode property.

Adding a Binding causes the CollectionChanged event to occur.

The following code example uses the Add method to add three Binding objects to the ControlBindingsCollection of a TextBox control. The ControlBindingsCollection is accessed through the DataBindings property of the Control class.

private void BindTextBoxProperties()
   // Clear the collection before adding new Binding objects.

   // Create a DataTable containing Color objects.
   DataTable t = MakeTable();

   /* Bind the Text, BackColor, and ForeColor properties
   to columns in the DataTable. */
   textBox1.DataBindings.Add("Text", t, "Text");
   textBox1.DataBindings.Add("BackColor", t, "BackColor");
   textBox1.DataBindings.Add("ForeColor", t, "ForeColor");

private DataTable MakeTable()
   /* Create a DataTable with three columns.
   Two of the columns contain Color objects. */

   DataTable t = new DataTable("Control");
   t.Columns.Add("BackColor", typeof(Color));
   t.Columns.Add("ForeColor", typeof(Color));

   // Add three rows to the table.
   DataRow r;

   r = t.NewRow();
   r["BackColor"] = Color.Blue;
   r["ForeColor"] = Color.Yellow;
   r["Text"] = "Yellow on Blue";

   r = t.NewRow();
   r["BackColor"] = Color.White;
   r["ForeColor"] = Color.Green;
   r["Text"] = "Green on white";

   r = t.NewRow();
   r["BackColor"] = Color.Orange;
   r["ForeColor"] = Color.Black;
   r["Text"] = "Black on Orange";

   return t;

.NET Framework
Available since 1.1
Return to top