Binding Constructor (String, Object, String)

Initializes a new instance of the Binding class that simple-binds the indicated control property to the specified data member of the data source.

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

public Binding(
	string propertyName,
	Object dataSource,
	string dataMember
)

Parameters

propertyName
Type: System.String

The name of the control property to bind.

dataSource
Type: System.Object

An Object that represents the data source.

dataMember
Type: System.String

The property or list to bind to.

ExceptionCondition
Exception

propertyName is neither a valid property of a control nor an empty string ("").

ArgumentException

The property given by propertyName does not exist on the control.

You can specify an instance of any of the following classes for the data source:

See the Binding class for more information about creating the dataMember string.

When you create a binding to a control's property, the new Binding inspects the events exposed by the bound control and attaches to two particular events:

If you attempt to bind to a property that does not exist, an ArgumentException will be thrown when the Binding is added to the control's Control.DataBindings collection.

The following code example binds a TextBox control to a table column in a DataSet named myDataSet. The example requires that you have declared myDataSet in the declarations section of the module.

private void CreateDataSet()
{
   myDataSet = new DataSet("myDataSet");
   /* Populates the DataSet with tables, relations, and 
      constraints. */
}

private void BindTextBoxToDataSet()
{
   /* Binds a TextBox control to a DataColumn named
   CompanyName in the DataTable named Suppliers. */
   textBox1.DataBindings.Add
   ("Text", myDataSet, "Suppliers.CompanyName");
}
   

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft