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。 |