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.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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.
| Exception | Condition |
|---|---|
| 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:
Any class that implements the IList interface
Any class
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:
An event named PropertyNameChanged (for example, Control::BackColorChanged)
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 = gcnew DataSet( "myDataSet" ); /* Populates the DataSet with tables, relations, and constraints. */ } void BindTextBoxToDataSet() { /* Binds a TextBox control to a DataColumn named CompanyName in the DataTable named Suppliers. */ textBox1->DataBindings->Add( "Text", myDataSet, "Suppliers.CompanyName" ); }
Available since 1.1