Binding Binding Binding Binding Constructors

定义

重载

Binding(String, Object, String) Binding(String, Object, String) Binding(String, Object, String) Binding(String, Object, String)

初始化 Binding 类的一个新实例,该类将指示的控件属性简单绑定到数据源的指定数据成员。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) Binding(String, Object, String, Boolean) Binding(String, Object, String, Boolean) Binding(String, Object, String, Boolean)

初始化 Binding 类的一个新实例,该实例将指示的控件属性绑定到数据源的指定数据成员,并启用要应用的格式设置(可选)。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) Binding(String, Object, String, Boolean, DataSourceUpdateMode) Binding(String, Object, String, Boolean, DataSourceUpdateMode)

初始化 Binding 类的新实例,该实例将指定的控件属性绑定到指定数据源的指定数据成员。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) Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object) Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object)

初始化 Binding 类的新实例,该实例将指示的控件属性绑定到指定数据源的指定数据成员。Initializes a new instance of the Binding class that binds the indicated control property to the specified data member of the specified data source. (可选)根据指定的更新设置,启用格式设置并将值传播到数据源,然后在从数据源返回 DBNull 时将该属性设置为指定值。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) Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String) Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

初始化 Binding 类的新实例,该实例将指定的控件属性绑定到指定数据源的指定数据成员。Initializes a new instance of the Binding class that binds the specified control property to the specified data member of the specified data source. (可选)允许用指定的格式字符串进行格式设置;根据指定的更新设置将值传播到数据源;在从数据源返回 DBNull 时将该属性设置为指定的值。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) Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider) Binding(String, Object, String, Boolean, DataSourceUpdateMode, Object, String, IFormatProvider)

初始化 Binding 类的新实例,并将指定的控件属性绑定到指定数据源的指定数据成员。Initializes a new instance of the Binding class with the specified control property to the specified data member of the specified data source. (可选)利用指定的格式字符串启用格式设置;根据指定的更新设置将值传播到数据源;利用指定的格式字符串启用格式设置;以及当从数据源返回 DBNull 时将属性设为指定值,并设置指定的格式提供程序。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) Binding(String, Object, String) Binding(String, Object, String) Binding(String, Object, String)

初始化 Binding 类的一个新实例,该类将指示的控件属性简单绑定到数据源的指定数据成员。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);
new System.Windows.Forms.Binding : string * obj * string -> System.Windows.Forms.Binding
Public Sub New (propertyName As String, dataSource As Object, dataMember As String)

参数

propertyName
String String String String

要绑定的控件属性的名称。The name of the control property to bind.

dataSource
Object Object Object Object

表示数据源的 ObjectAn Object that represents the data source.

dataMember
String String String String

要绑定到的属性或列表。The property or list to bind to.

异常

propertyName 既不是控件的有效属性,也不是空字符串 ("")。propertyName is neither a valid property of a control nor an empty string ("").

在该控件中不存在由 propertyName 给出的属性。The property given by propertyName does not exist on the control.

示例

下面的代码示例将TextBox控件绑定到指定myDataSetDataSet中的表列。The following code example binds a TextBox control to a table column in a DataSet named myDataSet. 该示例要求您已在模块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

注解

您可以为数据源指定以下任意类的实例:You can specify an instance of any of the following classes for the data source:

有关创建字符串的详细信息, 请参阅类。Binding dataMemberSee the Binding class for more information about creating the dataMember string.

创建到控件的属性的绑定时, 新Binding的将检查绑定控件公开的事件, 并附加到两个特定事件: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:

如果尝试绑定到不存在的属性, ArgumentException则会在将添加到控件的Control.DataBindings集合Binding时引发。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.

另请参阅

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

初始化 Binding 类的一个新实例,该实例将指示的控件属性绑定到数据源的指定数据成员,并启用要应用的格式设置(可选)。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);
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)

参数

propertyName
String String String String

要绑定的控件属性的名称。The name of the control property to bind.

dataSource
Object Object Object Object

表示数据源的 ObjectAn Object that represents the data source.

dataMember
String String String String

要绑定到的属性或列表。The property or list to bind to.

formattingEnabled
Boolean Boolean Boolean Boolean

若要格式化显示的数据,则为 true;否则为 falsetrue to format the displayed data; otherwise, false.

异常

在该控件中不存在由 propertyName 给出的属性。The property given by propertyName does not exist on the control.

- 或 --or- 给定的属性为只读属性。The property given is a read-only property.

禁用格式设置,且 propertyName 既不是有效的控件属性,也不是空字符串 ("")。Formatting is disabled and propertyName is neither a valid property of a control nor an empty string ("").

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

初始化 Binding 类的新实例,该实例将指定的控件属性绑定到指定数据源的指定数据成员。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);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode -> System.Windows.Forms.Binding

参数

propertyName
String String String String

要绑定的控件属性的名称。The name of the control property to bind.

dataSource
Object Object Object Object

表示数据源的 ObjectAn Object representing the data source.

dataMember
String String String String

要绑定到的属性或列表。The property or list to bind to.

formattingEnabled
Boolean Boolean Boolean Boolean

若要格式化显示的数据,则为 true;否则为 falsetrue to format the displayed data; otherwise, false.

异常

在该控件中不存在由 propertyName 给出的属性。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.

注解

您可以为数据源指定以下任意类的实例:You can specify an instance of any of the following classes for the data source:

有关创建字符串的详细信息, 请参阅类。Binding dataMemberSee the Binding class for more information about creating the dataMember string.

创建到控件的属性的绑定时, 新Binding的将检查绑定控件公开的事件, 并附加到两个特定事件: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:

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

初始化 Binding 类的新实例,该实例将指示的控件属性绑定到指定数据源的指定数据成员。Initializes a new instance of the Binding class that binds the indicated control property to the specified data member of the specified data source. (可选)根据指定的更新设置,启用格式设置并将值传播到数据源,然后在从数据源返回 DBNull 时将该属性设置为指定值。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);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj -> System.Windows.Forms.Binding

参数

propertyName
String String String String

要绑定的控件属性的名称。The name of the control property to bind.

dataSource
Object Object Object Object

表示数据源的 ObjectAn Object representing the data source.

dataMember
String String String String

要绑定到的属性或列表。The property or list to bind to.

formattingEnabled
Boolean Boolean Boolean Boolean

若要格式化显示的数据,则为 true;否则为 falsetrue to format the displayed data; otherwise, false.

nullValue
Object Object Object Object

当数据源值为 Object 时要应用于绑定控件属性的 DBNullThe Object to be applied to the bound control property if the data source value is DBNull.

异常

在该控件中不存在由 propertyName 给出的属性。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.

注解

您可以为数据源指定以下任意类的实例:You can specify an instance of any of the following classes for the data source:

有关创建字符串的详细信息, 请参阅类。Binding dataMemberSee the Binding class for more information about creating the dataMember string.

创建到控件的属性的绑定时, 新Binding的将检查绑定控件公开的事件, 并附加到两个特定事件: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:

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

初始化 Binding 类的新实例,该实例将指定的控件属性绑定到指定数据源的指定数据成员。Initializes a new instance of the Binding class that binds the specified control property to the specified data member of the specified data source. (可选)允许用指定的格式字符串进行格式设置;根据指定的更新设置将值传播到数据源;在从数据源返回 DBNull 时将该属性设置为指定的值。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);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj * string -> System.Windows.Forms.Binding

参数

propertyName
String String String String

要绑定的控件属性的名称。The name of the control property to bind.

dataSource
Object Object Object Object

表示数据源的 ObjectAn Object representing the data source.

dataMember
String String String String

要绑定到的属性或列表。The property or list to bind to.

formattingEnabled
Boolean Boolean Boolean Boolean

若要格式化显示的数据,则为 true;否则为 falsetrue to format the displayed data; otherwise, false.

nullValue
Object Object Object Object

当数据源值为 Object 时要应用于绑定控件属性的 DBNullThe Object to be applied to the bound control property if the data source value is DBNull.

formatString
String String String String

一个或多个格式说明符,指示如何显示值。One or more format specifier characters that indicate how a value is to be displayed.

异常

在该控件中不存在由 propertyName 给出的属性。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.

注解

您可以为数据源指定以下任意类的实例:You can specify an instance of any of the following classes for the data source:

有关创建字符串的详细信息, 请参阅类。Binding dataMemberSee the Binding class for more information about creating the dataMember string.

创建到控件的属性的绑定时, 新Binding的将检查绑定控件公开的事件, 并附加到两个特定事件: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:

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

初始化 Binding 类的新实例,并将指定的控件属性绑定到指定数据源的指定数据成员。Initializes a new instance of the Binding class with the specified control property to the specified data member of the specified data source. (可选)利用指定的格式字符串启用格式设置;根据指定的更新设置将值传播到数据源;利用指定的格式字符串启用格式设置;以及当从数据源返回 DBNull 时将属性设为指定值,并设置指定的格式提供程序。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);
new System.Windows.Forms.Binding : string * obj * string * bool * System.Windows.Forms.DataSourceUpdateMode * obj * string * IFormatProvider -> System.Windows.Forms.Binding

参数

propertyName
String String String String

要绑定的控件属性的名称。The name of the control property to bind.

dataSource
Object Object Object Object

表示数据源的 ObjectAn Object representing the data source.

dataMember
String String String String

要绑定到的属性或列表。The property or list to bind to.

formattingEnabled
Boolean Boolean Boolean Boolean

若要格式化显示的数据,则为 true;否则为 falsetrue to format the displayed data; otherwise, false.

nullValue
Object Object Object Object

当数据源值为 Object 时要应用于绑定控件属性的 DBNullThe Object to be applied to the bound control property if the data source value is DBNull.

formatString
String String String String

一个或多个格式说明符,指示如何显示值。One or more format specifier characters that indicate how a value is to be displayed.

formatInfo
IFormatProvider IFormatProvider IFormatProvider IFormatProvider

重写默认格式设置行为的 IFormatProvider 的实现。An implementation of IFormatProvider to override default formatting behavior.

异常

在该控件中不存在由 propertyName 给出的属性。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.

注解

您可以为数据源指定以下任意类的实例:You can specify an instance of any of the following classes for the data source:

有关创建字符串的详细信息, 请参阅类。Binding dataMemberSee the Binding class for more information about creating the dataMember string.

创建到控件的属性的绑定时, 新Binding的将检查绑定控件公开的事件, 并附加到两个特定事件: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:

适用于