共用方式為


ControlBindingsCollection 類別

定義

代表控制項的資料綁定集合。

public ref class ControlBindingsCollection : System::Windows::Forms::BindingsCollection
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
[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
[System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class ControlBindingsCollection : System.Windows.Forms.BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
    inherit BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
    inherit BindingsCollection
[<System.ComponentModel.TypeConverter("System.Windows.Forms.Design.ControlBindingsConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
type ControlBindingsCollection = class
    inherit BindingsCollection
Public Class ControlBindingsCollection
Inherits BindingsCollection
繼承
屬性

範例

以下程式碼範例將 Binding 物件加入五個控制項中的 a ControlBindingsCollection :四個 TextBox 控制項和一個 DateTimePicker 控制項。 是 ControlBindingsCollection 透過 DataBindings 類別的 Control 屬性來存取的。

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來完成的。 任何繼承自類別的Control物件都可以透過該DataBindings屬性存取。ControlBindingsCollection 有關支援資料綁定的 Windows 控制項清單,請參見該 Binding 類別。

包含 ControlBindingsCollection 標準的收集方法,如 AddClearRemove和 。

要取得屬於該 ControlBindingsCollection 物業的控制權,請使用該 Control 物業。

建構函式

名稱 Description
ControlBindingsCollection(IBindableComponent)

初始化一個新的類別實例 ControlBindingsCollection ,並指定可綁定控制。

屬性

名稱 Description
BindableComponent

會得到 IBindableComponent 裝訂收藏所屬的。

Control

他會取得收藏所屬的控制權。

Count

取得集合中總裝訂數量。

(繼承來源 BindingsCollection)
DefaultDataSourceUpdateMode

取得或設定集合中 a Binding 的預設DataSourceUpdateMode值。

IsReadOnly

會獲得一個值,表示該集合是否為唯讀。

(繼承來源 BaseCollection)
IsSynchronized

會取得一個值,表示存取是否 ICollection 同步。

(繼承來源 BaseCollection)
Item[Int32]

在指定的索引處得到 。Binding

(繼承來源 BindingsCollection)
Item[String]

會得到由控制項屬性名稱指定的。Binding

List

將綁定放在集合裡作為物件。

(繼承來源 BindingsCollection)
SyncRoot

取得一個物件,可用來同步存取 BaseCollection

(繼承來源 BaseCollection)

方法

名稱 Description
Add(Binding)

將指定的 Binding 資料加入集合。

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

建立綁定,將指定的控制屬性綁定至指定資料來源的指定資料成員,並可選擇性地啟用指定格式字串的格式化,根據指定的更新設定將值傳播至資料來源,從資料來源回傳時 DBNull 將屬性設定為指定值,設定指定的格式提供者, 並將裝訂加入收藏。

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

建立綁定,將指定的控制屬性綁定到指定資料來源的指定成員,並可選擇性啟用指定格式字串的格式化,根據指定的更新設定將值傳播到資料來源,從資料來源回傳時 DBNull 將屬性設定為指定值,並將綁定加入集合。

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

建立一個綁定,將指定的控制屬性綁定到指定資料來源的指定資料成員,並可選擇啟用格式化、根據指定的更新設定將值傳播到資料來源、從資料來源回傳時 DBNull 將屬性設定為指定值,並將綁定加入集合。

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

建立一個綁定,將指定的控制屬性綁定到指定資料來源的指定成員,並可選擇啟用格式化、根據指定的更新設定將值傳播到資料來源,並將綁定加入集合。

Add(String, Object, String, Boolean)

建立包含指定控制屬性名稱、資料來源、資料成員及是否啟用格式資訊的綁定,並將綁定加入集合。

Add(String, Object, String)

利用指定的控制屬性名稱、資料來源和資料成員建立 a Binding ,並將其加入集合。

AddCore(Binding)

為收藏加裝訂。

Clear()

清除收藏中的任何束縛。

ClearCore()

能清除收藏中的裝訂。

CopyTo(Array, Int32)

將目前一維Array中的所有元素從指定的目的Array索引開始,複製到指定的一維Array

(繼承來源 BaseCollection)
CreateObjRef(Type)

建立一個物件,包含產生代理伺服器所需的所有相關資訊,用於與遠端物件通訊。

(繼承來源 MarshalByRefObject)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

取得能夠遍歷集合成員的物件。

(繼承來源 BaseCollection)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

取得目前控制此實例生命週期政策的終身服務物件。

(繼承來源 MarshalByRefObject)
GetType()

取得目前實例的 Type

(繼承來源 Object)
InitializeLifetimeService()
已淘汰.

取得一個終身服務物件以控制此實例的終身政策。

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
MemberwiseClone(Boolean)

建立一個 MarshalByRefObject 目前物件的淺層複製品。

(繼承來源 MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

引發 CollectionChanged 事件。

(繼承來源 BindingsCollection)
OnCollectionChanging(CollectionChangeEventArgs)

引發 CollectionChanging 事件。

(繼承來源 BindingsCollection)
Remove(Binding)

從集合中刪除指定的 Binding 內容。

RemoveAt(Int32)

在指定的索引處刪除 。Binding

RemoveCore(Binding)

移除集合中指定的綁定。

ShouldSerializeMyAll()

會得到一個值,指示該集合是否應該序列化。

(繼承來源 BindingsCollection)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

事件

名稱 Description
CollectionChanged

發生於集合已變更時。

(繼承來源 BindingsCollection)
CollectionChanging

當收款即將變動時,會發生這種情況。

(繼承來源 BindingsCollection)

擴充方法

名稱 Description
AsParallel(IEnumerable)

啟用查詢的平行處理。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別篩選 IEnumerable 的專案。

適用於