Binding Constructors

Definition

Initializes a new instance of the Binding class.

Overloads

Binding(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.

Binding(String, Object, String, Boolean)

Initializes a new instance of the Binding class that binds the indicated control property to the specified data member of the data source, and optionally enables formatting to be applied.

Binding(String, Object, String, Boolean, DataSourceUpdateMode)

Initializes a new instance of the Binding class that binds the specified control property to the specified data member of the specified data source. Optionally enables formatting and propagates values to the data source based on the specified update setting.

Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object)

Initializes a new instance of the Binding class that binds the indicated control property to the specified data member of the specified data source. Optionally enables formatting, propagates values to the data source based on the specified update setting, and sets the property to the specified value when a DBNull is returned from the data source.

Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

Initializes a new instance of the Binding class that binds the specified control property to the specified data member of the specified data source. Optionally enables formatting with the specified format string; propagates values to the data source based on the specified update setting; and sets the property to the specified value when a DBNull is returned from the data source.

Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)

Initializes a new instance of the Binding class with the specified control property to the specified data member of the specified data source. Optionally enables formatting with the specified format string; propagates values to the data source based on the specified update setting; enables formatting with the specified format string; sets the property to the specified value when a DBNull is returned from the data source; and sets the specified format provider.

Binding(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.

public:
 Binding(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember);
public Binding (string propertyName, object dataSource, string dataMember);
public Binding (string propertyName, object? dataSource, string? dataMember);
new System.Windows.Forms.Binding : string * obj * string -> System.Windows.Forms.Binding
Public Sub New (propertyName As String, dataSource As Object, dataMember As String)

Parameters

propertyName
String

The name of the control property to bind.

dataSource
Object

An Object that represents the data source.

dataMember
String

The property or list to bind to.

Exceptions

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

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

Examples

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" );
   }
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");
}
Private Sub CreateDataSet
   myDataSet = new DataSet("myDataSet")
   ' Populates the DataSet with tables, relations, and
   ' constraints.
End Sub

Private Sub BindTextBoxToDataSet 
   ' Binds a TextBox control to a column in the DataSet.
   textBox1.DataBindings.Add _
   ("Text", myDataSet, "Suppliers.CompanyName")
End Sub

Remarks

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.

See also

Applies to

Binding(String, Object, String, Boolean)

Initializes a new instance of the Binding class that binds the indicated control property to the specified data member of the data source, and optionally enables formatting to be applied.

public:
 Binding(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled);
public Binding (string propertyName, object dataSource, string dataMember, bool formattingEnabled);
public Binding (string propertyName, object? dataSource, string? dataMember, bool formattingEnabled);
new System.Windows.Forms.Binding : string * obj * string * bool -> System.Windows.Forms.Binding
Public Sub New (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean)

Parameters

propertyName
String

The name of the control property to bind.

dataSource
Object

An Object that represents the data source.

dataMember
String

The property or list to bind to.

formattingEnabled
Boolean

true to format the displayed data; otherwise, false.

Exceptions

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

-or-

The property given is a read-only property.

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

Applies to

Binding(String, Object, String, Boolean, DataSourceUpdateMode)

Initializes a new instance of the Binding class that binds the specified control property to the specified data member of the specified data source. Optionally enables formatting and propagates values to the data source based on the specified update setting.

public:
 Binding(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode dataSourceUpdateMode);
public Binding (string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode);
public Binding (string propertyName, object? dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode -> System.Windows.Forms.Binding
Public Sub New (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, dataSourceUpdateMode As DataSourceUpdateMode)

Parameters

propertyName
String

The name of the control property to bind.

dataSource
Object

An Object representing the data source.

dataMember
String

The property or list to bind to.

formattingEnabled
Boolean

true to format the displayed data; otherwise, false.

dataSourceUpdateMode
DataSourceUpdateMode

One of the DataSourceUpdateMode values.

Exceptions

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

-or-

The data source or data member or control property specified are associated with another binding in the collection.

Remarks

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:

Applies to

Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object)

Initializes a new instance of the Binding class that binds the indicated control property to the specified data member of the specified data source. Optionally enables formatting, propagates values to the data source based on the specified update setting, and sets the property to the specified value when a DBNull is returned from the data source.

public:
 Binding(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode dataSourceUpdateMode, System::Object ^ nullValue);
public Binding (string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode, object nullValue);
public Binding (string propertyName, object? dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode, object? nullValue);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj -> System.Windows.Forms.Binding
Public Sub New (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, dataSourceUpdateMode As DataSourceUpdateMode, nullValue As Object)

Parameters

propertyName
String

The name of the control property to bind.

dataSource
Object

An Object representing the data source.

dataMember
String

The property or list to bind to.

formattingEnabled
Boolean

true to format the displayed data; otherwise, false.

dataSourceUpdateMode
DataSourceUpdateMode

One of the DataSourceUpdateMode values.

nullValue
Object

The Object to be applied to the bound control property if the data source value is DBNull.

Exceptions

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

-or-

The data source or data member or control property specified are associated with another binding in the collection.

Remarks

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:

Applies to

Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

Initializes a new instance of the Binding class that binds the specified control property to the specified data member of the specified data source. Optionally enables formatting with the specified format string; propagates values to the data source based on the specified update setting; and sets the property to the specified value when a DBNull is returned from the data source.

public:
 Binding(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode dataSourceUpdateMode, System::Object ^ nullValue, System::String ^ formatString);
public Binding (string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode, object nullValue, string formatString);
public Binding (string propertyName, object? dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode, object? nullValue, string formatString);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj * string -> System.Windows.Forms.Binding
Public Sub New (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, dataSourceUpdateMode As DataSourceUpdateMode, nullValue As Object, formatString As String)

Parameters

propertyName
String

The name of the control property to bind.

dataSource
Object

An Object representing the data source.

dataMember
String

The property or list to bind to.

formattingEnabled
Boolean

true to format the displayed data; otherwise, false.

dataSourceUpdateMode
DataSourceUpdateMode

One of the DataSourceUpdateMode values.

nullValue
Object

The Object to be applied to the bound control property if the data source value is DBNull.

formatString
String

One or more format specifier characters that indicate how a value is to be displayed.

Exceptions

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

-or-

The data source or data member or control property specified are associated with another binding in the collection.

Remarks

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:

Applies to

Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)

Initializes a new instance of the Binding class with the specified control property to the specified data member of the specified data source. Optionally enables formatting with the specified format string; propagates values to the data source based on the specified update setting; enables formatting with the specified format string; sets the property to the specified value when a DBNull is returned from the data source; and sets the specified format provider.

public:
 Binding(System::String ^ propertyName, System::Object ^ dataSource, System::String ^ dataMember, bool formattingEnabled, System::Windows::Forms::DataSourceUpdateMode dataSourceUpdateMode, System::Object ^ nullValue, System::String ^ formatString, IFormatProvider ^ formatInfo);
public Binding (string propertyName, object dataSource, string dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode, object nullValue, string formatString, IFormatProvider formatInfo);
public Binding (string propertyName, object? dataSource, string? dataMember, bool formattingEnabled, System.Windows.Forms.DataSourceUpdateMode dataSourceUpdateMode, object? nullValue, string formatString, IFormatProvider? formatInfo);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj * string * IFormatProvider -> System.Windows.Forms.Binding
Public Sub New (propertyName As String, dataSource As Object, dataMember As String, formattingEnabled As Boolean, dataSourceUpdateMode As DataSourceUpdateMode, nullValue As Object, formatString As String, formatInfo As IFormatProvider)

Parameters

propertyName
String

The name of the control property to bind.

dataSource
Object

An Object representing the data source.

dataMember
String

The property or list to bind to.

formattingEnabled
Boolean

true to format the displayed data; otherwise, false.

dataSourceUpdateMode
DataSourceUpdateMode

One of the DataSourceUpdateMode values.

nullValue
Object

The Object to be applied to the bound control property if the data source value is DBNull.

formatString
String

One or more format specifier characters that indicate how a value is to be displayed.

formatInfo
IFormatProvider

An implementation of IFormatProvider to override default formatting behavior.

Exceptions

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

-or-

The data source or data member or control property specified are associated with another binding in the collection.

Remarks

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:

Applies to