ControlBindingsCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表控制項的資料繫結集合。
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 至五個控制項的 :四 TextBox 個 ControlBindingsCollection 控制項和一個 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包含標準集合方法,例如 Add 、 Clear 和 Remove 。
若要取得 所屬的 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) |
方法
事件
CollectionChanged |
發生於集合變更時。 (繼承來源 BindingsCollection) |
CollectionChanging |
發生於集合將要變更時。 (繼承來源 BindingsCollection) |
擴充方法
Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
OfType<TResult>(IEnumerable) |
根據指定的型別來篩選 IEnumerable 的項目。 |
AsParallel(IEnumerable) |
啟用查詢的平行化作業。 |
AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |