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 至五個控制項的 :四 TextBoxControlBindingsCollection 控制項和一個 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

備註

簡單的資料系結是藉由將 物件加入 BindingControlBindingsCollection 來完成。 繼承自 Control 類別的任何物件都可以透過 DataBindings 屬性存取 ControlBindingsCollection 。 如需支援資料系結的 Windows 控制項清單,請參閱 類別 Binding

ControlBindingsCollection包含標準集合方法,例如 AddClearRemove

若要取得 所屬的 ControlBindingsCollection 控制項,請使用 Control 屬性。

建構函式

ControlBindingsCollection(IBindableComponent)

使用指定的可繫結控制項,初始化 ControlBindingsCollection 類別的新執行個體。

屬性

BindableComponent

取得繫結集合所屬的 IBindableComponent

Control

取得集合所屬的控制項。

Count

取得集合中的繫結總數。

(繼承來源 BindingsCollection)
DefaultDataSourceUpdateMode

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

IsReadOnly

取得值,表示集合是否為唯讀。

(繼承來源 BaseCollection)
IsSynchronized

取得值,表示對 ICollection 的存取是否同步化。

(繼承來源 BaseCollection)
Item[Int32]

取得指定索引處的 Binding

(繼承來源 BindingsCollection)
Item[String]

取得由控制項屬性名稱指定的 Binding

List

取得集合中當做物件的繫結。

(繼承來源 BindingsCollection)
SyncRoot

取得可用以同步存取 BaseCollection 的物件。

(繼承來源 BaseCollection)

方法

Add(Binding)

將指定的 Binding 加入至集合。

Add(String, Object, String)

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

Add(String, Object, String, Boolean)

使用指定的控制項屬性名稱、資料來源、資料成員和是否啟用格式化的相關資訊,來建立繫結,並將該繫結加入集合。

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

建立繫結,以便將指定的控制項屬性繫結至指定資料來源的指定資料成員、選擇性地啟用格式化、根據指定的更新設定將值傳送至資料來源,以及將繫結加入集合。

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

建立繫結,以便將指定的控制項屬性繫結至指定資料來源的指定資料成員、選擇性地啟用格式化、根據指定的更新設定將值傳送至資料來源、從資料來源傳回 DBNull 時將屬性設定為指定的值,以及將繫結加入集合。

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

建立繫結,以便將指定的控制項屬性繫結至指定資料來源的指定資料成員、選擇性地使用指定的格式字串啟用格式化、根據指定的更新設定將值傳送至資料來源、從資料來源傳回 DBNull 時將屬性設定為指定的值,以及將繫結加入集合。

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

建立繫結,以便將指定的控制項屬性繫結至指定資料來源的指定資料成員、選擇性地使用指定的格式字串啟用格式化、根據指定的更新設定將值傳送至資料來源、從資料來源傳回 DBNull 時將屬性設定為指定的值、設定指定的格式提供者,以及將繫結加入集合。

AddCore(Binding)

將繫結加入集合。

Clear()

清除所有繫結的集合。

ClearCore()

清除集合中的繫結。

CopyTo(Array, Int32)

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

(繼承來源 BaseCollection)
CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Equals(Object)

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

(繼承來源 Object)
GetEnumerator()

取得允許逐一查看集合之成員的物件。

(繼承來源 BaseCollection)
GetHashCode()

做為預設雜湊函式。

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

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 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)

事件

CollectionChanged

發生於集合變更時。

(繼承來源 BindingsCollection)
CollectionChanging

發生於集合將要變更時。

(繼承來源 BindingsCollection)

擴充方法

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於