ControlBindingsCollection ControlBindingsCollection ControlBindingsCollection ControlBindingsCollection Class

定义

代表控件的数据绑定的集合。Represents the collection of data bindings for a control.

public ref class ControlBindingsCollection : System::Windows::Forms::BindingsCollection
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
type ControlBindingsCollection = class
    inherit BindingsCollection
Public Class ControlBindingsCollection
Inherits BindingsCollection
继承
属性

示例

下面的代码示例将Binding对象添加ControlBindingsCollection到五个控件中: TextBox四个控件DateTimePicker和一个控件。The following code example adds Binding objects to a ControlBindingsCollection of five controls: four TextBox controls and a DateTimePicker control. 通过 ControlBindingsCollection 类的 DataBindings 属性来访问 ControlThe ControlBindingsCollection is accessed through the DataBindings property of the Control class.

protected:
   void BindControls()
   {
      /* Create two Binding objects for the first two TextBox 
         controls. The data-bound property for both controls 
         is the Text property. The data source is a DataSet 
         (ds). The data member is the navigation path: 
         TableName.ColumnName. */
      textBox1->DataBindings->Add( gcnew Binding(
         "Text",ds,"customers.custName" ) );
      textBox2->DataBindings->Add( gcnew Binding(
         "Text",ds,"customers.custID" ) );
      
      /* Bind the DateTimePicker control by adding a new Binding. 
         The data member of the DateTimePicker is a navigation path:
         TableName.RelationName.ColumnName. */
      DateTimePicker1->DataBindings->Add( gcnew Binding(
         "Value",ds,"customers.CustToOrders.OrderDate" ) );
      
      /* Create a new Binding using the DataSet and a 
         navigation path(TableName.RelationName.ColumnName).
         Add event delegates for the Parse and Format events to 
         the Binding object, and add the object to the third 
         TextBox control's BindingsCollection. The delegates 
         must be added before adding the Binding to the 
         collection; otherwise, no formatting occurs until 
         the Current object of the BindingManagerBase for 
         the data source changes. */
      Binding^ b = gcnew Binding(
         "Text",ds,"customers.custToOrders.OrderAmount" );
      b->Parse += gcnew ConvertEventHandler(
         this, &Form1::CurrencyStringToDecimal );
      b->Format += gcnew ConvertEventHandler(
         this, &Form1::DecimalToCurrencyString );
      textBox3->DataBindings->Add( b );
      
      /*Bind the fourth TextBox to the Value of the 
         DateTimePicker control. This demonstates how one control
         can be data-bound to another.*/
      textBox4->DataBindings->Add( "Text", DateTimePicker1, "Value" );
      
      // Get the BindingManagerBase for the textBox4 Binding.
      BindingManagerBase^ bmText = this->BindingContext[
         DateTimePicker1 ];
      
      /* Print the Type of the BindingManagerBase, which is 
         a PropertyManager because the data source
         returns only a single property value. */
      Console::WriteLine( bmText->GetType() );
      
      // Print the count of managed objects, which is one.
      Console::WriteLine( bmText->Count );
      
      // Get the BindingManagerBase for the Customers table. 
      bmCustomers = this->BindingContext[ds, "Customers"];
      
      /* Print the Type and count of the BindingManagerBase.
         Because the data source inherits from IBindingList,
         it is a RelatedCurrencyManager (a derived class of
         CurrencyManager). */
      Console::WriteLine( bmCustomers->GetType() );
      Console::WriteLine( bmCustomers->Count );
      
      /* Get the BindingManagerBase for the Orders of the current
         customer using a navigation path: TableName.RelationName. */
      bmOrders = this->BindingContext[ds, "customers.CustToOrders"];
   }
protected void BindControls()
{
   /* Create two Binding objects for the first two TextBox 
   controls. The data-bound property for both controls 
   is the Text property. The data source is a DataSet 
   (ds). The data member is the navigation path: 
   TableName.ColumnName. */
   textBox1.DataBindings.Add(new Binding
   ("Text", ds, "customers.custName"));
   textBox2.DataBindings.Add(new Binding
   ("Text", ds, "customers.custID"));
      
   /* Bind the DateTimePicker control by adding a new Binding. 
   The data member of the DateTimePicker is a navigation path:
   TableName.RelationName.ColumnName. */
   DateTimePicker1.DataBindings.Add(new 
   Binding("Value", ds, "customers.CustToOrders.OrderDate"));

   /* Create a new Binding using the DataSet and a 
   navigation path(TableName.RelationName.ColumnName).
   Add event delegates for the Parse and Format events to 
   the Binding object, and add the object to the third 
   TextBox control's BindingsCollection. The delegates 
   must be added before adding the Binding to the 
   collection; otherwise, no formatting occurs until 
   the Current object of the BindingManagerBase for 
   the data source changes. */
   Binding b = new Binding
   ("Text", ds, "customers.custToOrders.OrderAmount");
   b.Parse+=new ConvertEventHandler(CurrencyStringToDecimal);
   b.Format+=new ConvertEventHandler(DecimalToCurrencyString);
   textBox3.DataBindings.Add(b);

   /*Bind the fourth TextBox to the Value of the 
   DateTimePicker control. This demonstates how one control
   can be data-bound to another.*/
   textBox4.DataBindings.Add("Text", DateTimePicker1,"Value");

   // Get the BindingManagerBase for the textBox4 Binding.
   BindingManagerBase bmText = this.BindingContext
   [DateTimePicker1];

   /* Print the Type of the BindingManagerBase, which is 
   a PropertyManager because the data source
   returns only a single property value. */
   Console.WriteLine(bmText.GetType().ToString());

   // Print the count of managed objects, which is one.
   Console.WriteLine(bmText.Count);

   // Get the BindingManagerBase for the Customers table. 
   bmCustomers = this.BindingContext [ds, "Customers"];

   /* Print the Type and count of the BindingManagerBase.
   Because the data source inherits from IBindingList,
   it is a RelatedCurrencyManager (a derived class of
   CurrencyManager). */
   Console.WriteLine(bmCustomers.GetType().ToString());
   Console.WriteLine(bmCustomers.Count);
   
   /* Get the BindingManagerBase for the Orders of the current
   customer using a navigation path: TableName.RelationName. */ 
   bmOrders = this.BindingContext[ds, "customers.CustToOrders"];
}
Protected Sub BindControls()
    ' Create two Binding objects for the first two TextBox 
    ' controls. The data-bound property for both controls 
    ' is the Text property. The data source is a DataSet 
    ' (ds). The data member is the navigation path: 
    ' TableName.ColumnName. 
    textBox1.DataBindings.Add _
       (New Binding("Text", ds, "customers.custName"))
    textBox2.DataBindings.Add _
       (New Binding("Text", ds, "customers.custID"))
    
    ' Bind the DateTimePicker control by adding a new Binding. 
    ' The data member of the DateTimePicker is a navigation path:
    ' TableName.RelationName.ColumnName. 
    DateTimePicker1.DataBindings.Add _
       (New Binding("Value", ds, "customers.CustToOrders.OrderDate"))
    
    ' Create a new Binding using the DataSet and a 
    ' navigation path(TableName.RelationName.ColumnName).
    ' Add event delegates for the Parse and Format events to 
    ' the Binding object, and add the object to the third 
    ' TextBox control's BindingsCollection. The delegates 
    ' must be added before adding the Binding to the 
    ' collection; otherwise, no formatting occurs until 
    ' the Current object of the BindingManagerBase for 
    ' the data source changes. 
    Dim b As New Binding("Text", ds, "customers.custToOrders.OrderAmount")
    AddHandler b.Parse, AddressOf CurrencyStringToDecimal
    AddHandler b.Format, AddressOf DecimalToCurrencyString
    textBox3.DataBindings.Add(b)
    
    ' Bind the fourth TextBox to the Value of the 
    ' DateTimePicker control. This demonstates how one control
    ' can be data-bound to another.
    textBox4.DataBindings.Add("Text", DateTimePicker1, "Value")
    
    ' Get the BindingManagerBase for the textBox4 Binding.
    Dim bmText As BindingManagerBase = Me.BindingContext(DateTimePicker1)
    
    ' Print the Type of the BindingManagerBase, which is 
    ' a PropertyManager because the data source
    ' returns only a single property value. 
    Console.WriteLine(bmText.GetType().ToString())
    
    ' Print the count of managed objects, which is one.
    Console.WriteLine(bmText.Count)
    
    ' Get the BindingManagerBase for the Customers table. 
    bmCustomers = Me.BindingContext(ds, "Customers")
    
    ' Print the Type and count of the BindingManagerBase.
    ' Because the data source inherits from IBindingList,
    ' it is a RelatedCurrencyManager (a derived class of
    ' CurrencyManager). 
    Console.WriteLine(bmCustomers.GetType().ToString())
    Console.WriteLine(bmCustomers.Count)
    
    ' Get the BindingManagerBase for the Orders of the current
    ' customer using a navigation path: TableName.RelationName. 
    bmOrders = Me.BindingContext(ds, "customers.CustToOrders")
End Sub    

注解

简单的数据绑定通过将对象Binding添加ControlBindingsCollection到来完成。Simple data binding is accomplished by adding Binding objects to a ControlBindingsCollection. Control类继承的任何对象都可以ControlBindingsCollection通过DataBindings属性访问。Any object that inherits from the Control class can access the ControlBindingsCollection through the DataBindings property. 有关支持数据绑定的 Windows 控件的列表, 请参见Binding类。For a list of Windows controls that support data binding, see the Binding class.

包含标准的集合方法Add, 例如、 ClearRemoveControlBindingsCollectionThe ControlBindingsCollection contains standard collection methods such as Add, Clear, and Remove.

若要获取ControlBindingsCollection属于的控件, 请Control使用属性。To get the control that the ControlBindingsCollection belongs to, use the Control property.

构造函数

ControlBindingsCollection(IBindableComponent) ControlBindingsCollection(IBindableComponent) ControlBindingsCollection(IBindableComponent) ControlBindingsCollection(IBindableComponent)

用指定的可绑定控件初始化 ControlBindingsCollection 类的新实例。Initializes a new instance of the ControlBindingsCollection class with the specified bindable control.

属性

BindableComponent BindableComponent BindableComponent BindableComponent

获取绑定集合所属的 IBindableComponentGets the IBindableComponent the binding collection belongs to.

Control Control Control Control

获取该集合所属的控件。Gets the control that the collection belongs to.

Count Count Count Count

获取集合中绑定的总数。Gets the total number of bindings in the collection.

(Inherited from BindingsCollection)
DefaultDataSourceUpdateMode DefaultDataSourceUpdateMode DefaultDataSourceUpdateMode DefaultDataSourceUpdateMode

获取或设置集合中的 Binding 的默认 DataSourceUpdateModeGets or sets the default DataSourceUpdateMode for a Binding in the collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

获取一个值,该值指示集合是否为只读。Gets a value indicating whether the collection is read-only.

(Inherited from BaseCollection)
IsSynchronized IsSynchronized IsSynchronized IsSynchronized

获取一个值,该值指示对 ICollection 的访问是否同步。Gets a value indicating whether access to the ICollection is synchronized.

(Inherited from BaseCollection)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

获取位于指定索引处的 BindingGets the Binding at the specified index.

(Inherited from BindingsCollection)
Item[String] Item[String] Item[String] Item[String]

获取由控件的属性名指定的 BindingGets the Binding specified by the control's property name.

List List List List

获取集合中作为对象的绑定。Gets the bindings in the collection as an object.

(Inherited from BindingsCollection)
SyncRoot SyncRoot SyncRoot SyncRoot

获取可用于同步对 BaseCollection 的访问的对象。Gets an object that can be used to synchronize access to the BaseCollection.

(Inherited from BaseCollection)

方法

Add(Binding) Add(Binding) Add(Binding) Add(Binding)

将指定的 Binding 添加到集合。Adds the specified Binding to the collection.

Add(String, Object, String) Add(String, Object, String) Add(String, Object, String) Add(String, Object, String)

使用指定的控件属性名、数据源和数据成员创建 Binding,并将其添加到集合中。Creates a Binding using the specified control property name, data source, and data member, and adds it to the collection.

Add(String, Object, String, Boolean) Add(String, Object, String, Boolean) Add(String, Object, String, Boolean) Add(String, Object, String, Boolean)

用指定的控件属性名称、数据源、数据成员以及有关格式设置是否启用的信息创建绑定,并将该绑定添加到集合中。Creates a binding with the specified control property name, data source, data member, and information about whether formatting is enabled, and adds the binding to the collection.

Add(String, Object, String, Boolean, DataSourceUpdateMode) Add(String, Object, String, Boolean, DataSourceUpdateMode) Add(String, Object, String, Boolean, DataSourceUpdateMode) Add(String, Object, String, Boolean, DataSourceUpdateMode)

创建将指定控件属性绑定到指定数据源的指定数据成员的绑定,同时可选地启用格式设置,根据指定的更新设置将值传播到数据源,并将该绑定添加到集合。Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting, propagating values to the data source based on the specified update setting, and adding the binding to the collection.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object) Add(String, Object, String, Boolean, DataSourceUpdateMode, Object) Add(String, Object, String, Boolean, DataSourceUpdateMode, Object) Add(String, Object, String, Boolean, DataSourceUpdateMode, Object)

创建将指定控件属性绑定到指定数据源的指定数据成员的绑定,同时可选地启用格式设置,根据指定的更新设置将值传播到数据源,当从数据源返回 DBNull 时将该属性设置为指定的值,并将该绑定添加到集合。Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting, propagating values to the data source based on the specified update setting, setting the property to the specified value when DBNull is returned from the data source, and adding the binding to the collection.

Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String) Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String) Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String) Add(String, Object, String, Boolean, DataSourceUpdateMode, Object, String)

创建将指定控件属性绑定到指定数据源的指定数据成员的绑定,同时可选地以指定的格式字符串启用格式设置、根据指定的更新设置将值传播到数据源、当从数据源返回 DBNull 时将该属性设置为指定的值,并将该绑定添加到集合。Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting with the specified format string, propagating values to the data source based on the specified update setting, setting the property to the specified value when DBNull is returned from the data source, and adding the binding to the collection.

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

创建将指定控件属性绑定到指定数据源的指定数据成员的绑定,同时可选地以指定的格式字符串启用格式设置、根据指定的更新设置将值传播到数据源、当从数据源返回 DBNull 时将该属性设置为指定的值、设置指定的格式提供程序,并将该绑定添加到集合。Creates a binding that binds the specified control property to the specified data member of the specified data source, optionally enabling formatting with the specified format string, propagating values to the data source based on the specified update setting, setting the property to the specified value when DBNull is returned from the data source, setting the specified format provider, and adding the binding to the collection.

AddCore(Binding) AddCore(Binding) AddCore(Binding) AddCore(Binding)

将绑定添加到集合中。Adds a binding to the collection.

Clear() Clear() Clear() Clear()

清除集合的所有绑定。Clears the collection of any bindings.

ClearCore() ClearCore() ClearCore() ClearCore()

清除集合中的绑定。Clears the bindings in the collection.

CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

将当前一维 Array 的所有元素复制到指定的一维 Array 中(从指定的目标 Array 索引开始)。Copies all the elements of the current one-dimensional Array to the specified one-dimensional Array starting at the specified destination Array index.

(Inherited from BaseCollection)
CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

获取能够循环访问集合成员的对象。Gets the object that enables iterating through the members of the collection.

(Inherited from BaseCollection)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs) OnCollectionChanged(CollectionChangeEventArgs)

引发 CollectionChanged 事件。Raises the CollectionChanged event.

(Inherited from BindingsCollection)
OnCollectionChanging(CollectionChangeEventArgs) OnCollectionChanging(CollectionChangeEventArgs) OnCollectionChanging(CollectionChangeEventArgs) OnCollectionChanging(CollectionChangeEventArgs)

引发 CollectionChanging 事件。Raises the CollectionChanging event.

(Inherited from BindingsCollection)
Remove(Binding) Remove(Binding) Remove(Binding) Remove(Binding)

从集合中删除指定的 BindingDeletes the specified Binding from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

删除指定索引处的 BindingDeletes the Binding at the specified index.

RemoveCore(Binding) RemoveCore(Binding) RemoveCore(Binding) RemoveCore(Binding)

从集合中移除指定的绑定。Removes the specified binding from the collection.

ShouldSerializeMyAll() ShouldSerializeMyAll() ShouldSerializeMyAll() ShouldSerializeMyAll()

获取指示是否应序列化集合的值。Gets a value that indicates whether the collection should be serialized.

(Inherited from BindingsCollection)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

事件

CollectionChanged CollectionChanged CollectionChanged CollectionChanged

在集合更改后发生。Occurs when the collection has changed.

(Inherited from BindingsCollection)
CollectionChanging CollectionChanging CollectionChanging CollectionChanging

在集合即将更改时发生。Occurs when the collection is about to change.

(Inherited from BindingsCollection)

扩展方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于