ControlBindingsCollection 클래스
컨트롤에 대한 데이터 바인딩의 컬렉션을 나타냅니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
Public Class ControlBindingsCollection
Inherits BindingsCollection
‘사용 방법
Dim instance As ControlBindingsCollection
public class ControlBindingsCollection : BindingsCollection
public ref class ControlBindingsCollection : public BindingsCollection
public class ControlBindingsCollection extends BindingsCollection
public class ControlBindingsCollection extends BindingsCollection
설명
단순 데이터 바인딩은 ControlBindingsCollection에 Binding 개체를 추가하면 수행됩니다. Control 클래스에서 상속되는 모든 개체는 DataBindings 속성을 사용하여 ControlBindingsCollection에 액세스할 수 있습니다. 데이터 바인딩을 지원하는 Windows 컨트롤 목록을 보려면 Binding 클래스를 참조하십시오.
ControlBindingsCollection에는 Add, Clear 및 Remove와 같은 표준 컬렉션 메서드가 포함됩니다.
ControlBindingsCollection이 속한 컨트롤을 가져오려면 Control 속성을 사용합니다.
예제
다음 코드 예제에서는 TextBox 컨트롤 네 개와 DateTimePicker 컨트롤 하나로 구성된 ControlBindingsCollection에 Binding 개체를 추가합니다. ControlBindingsCollection에는 Control 클래스의 DataBindings 속성을 통해 액세스합니다.
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
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:
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.get_DataBindings().
Add(new Binding("Text", ds, "customers.custName"));
textBox2.get_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.get_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.add_Parse(new ConvertEventHandler(CurrencyStringToDecimal));
b.add_Format(new ConvertEventHandler(DecimalToCurrencyString));
textBox3.get_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.get_DataBindings().Add("Text", dateTimePicker1, "Value");
// Get the BindingManagerBase for the textBox4 Binding.
BindingManagerBase bmText
= this.get_BindingContext().get_Item(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.get_Count());
// Get the BindingManagerBase for the Customers table.
bmCustomers = this.get_BindingContext().get_Item(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.get_Count());
/* Get the BindingManagerBase for the Orders of the current
customer using a navigation path: TableName.RelationName.
*/
bmOrders
= this.get_BindingContext().get_Item(ds, "customers.CustToOrders");
} //BindControls
상속 계층 구조
System.Object
System.MarshalByRefObject
System.Windows.Forms.BaseCollection
System.Windows.Forms.BindingsCollection
System.Windows.Forms.ControlBindingsCollection
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0, 1.0에서 지원