BindingContext 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
클래스에서 BindingManagerBase 상속되는 모든 개체의 Control 개체 컬렉션을 관리합니다.
public ref class BindingContext : System::Collections::ICollection
public class BindingContext : System.Collections.ICollection
type BindingContext = class
interface ICollection
interface IEnumerable
Public Class BindingContext
Implements ICollection
- 상속
-
BindingContext
- 구현
예제
다음 코드 예제에서는 5개의 컨트롤(a DateTimePicker 및 4 Binding 개의 컨트롤)을 여러 데이터 원본에 바인딩하는 네 TextBox 개의 개체를 만듭니다. BindingContext 그런 다음 각 데이터 원본에 대한 값을 BindingManagerBase 가져오는 데 사용됩니다.
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 a navigation path in the form:
"TableName.ColumnName". */
text1->DataBindings->Add( gcnew Binding( "Text",ds,"customers.custName" ) );
text2->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 string. */
DateTimePicker1->DataBindings->Add( gcnew Binding( "Value",ds,"customers.CustToOrders.OrderDate" ) );
/* Add event delegates for the Parse and Format events to a
new 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 );
text3->DataBindings->Add( b );
// Get the BindingManagerBase for the Customers table.
bmCustomers = this->BindingContext[ ds,"Customers" ];
/* Get the BindingManagerBase for the Orders table using the
RelationName. */
bmOrders = this->BindingContext[ds, "customers.CustToOrders"];
/* Bind the fourth TextBox control's Text property to the
third control's Text property. */
text4->DataBindings->Add( "Text", text3, "Text" );
}
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 a navigation path in the form:
"TableName.ColumnName". */
text1.DataBindings.Add(new Binding
("Text", ds, "customers.custName"));
text2.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 string. */
DateTimePicker1.DataBindings.Add(new
Binding("Value", ds, "customers.CustToOrders.OrderDate"));
/* Add event delegates for the Parse and Format events to a
new 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);
text3.DataBindings.Add(b);
// Get the BindingManagerBase for the Customers table.
bmCustomers = this.BindingContext [ds, "Customers"];
/* Get the BindingManagerBase for the Orders table using the
RelationName. */
bmOrders = this.BindingContext[ds, "customers.CustToOrders"];
/* Bind the fourth TextBox control's Text property to the
third control's Text property. */
text4.DataBindings.Add("Text", text3, "Text");
}
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 string
' "TableName.ColumnName".
text1.DataBindings.Add(New Binding _
("Text", ds, "customers.custName"))
text2.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
' TableName.RelationName.ColumnName string.
DateTimePicker1.DataBindings.Add(New Binding _
("Value", ds, "customers.CustToOrders.OrderDate"))
' Add event delegates for the Parse and Format events to a
' new 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 Binding = New Binding _
("Text", ds, "customers.custToOrders.OrderAmount")
AddHandler b.Parse, New ConvertEventHandler(AddressOf CurrencyStringToDecimal)
AddHandler b.Format, New ConvertEventHandler(AddressOf DecimalToCurrencyString)
text3.DataBindings.Add(b)
' Get the BindingManagerBase for the Customers table.
bmCustomers = Me.BindingContext(ds, "Customers")
' Get the BindingManagerBase for the Orders table using the
' RelationName.
bmOrders = Me.BindingContext(ds, "customers.CustToOrders")
' Bind the fourth TextBox control's Text property to the
' third control's Text property.
text4.DataBindings.Add("Text", text3, "Text")
End Sub
설명
각 Windows Form에는 폼의 BindingManagerBase 개체를 관리하는 하나 이상의 BindingContext 개체가 있습니다. 클래스는 BindingManagerBase 추상이므로 속성의 Item[] 반환 형식은 a CurrencyManager 또는 a PropertyManager입니다. 데이터 원본이 개체 목록 대신 단일 속성만 반환할 수 있는 개체인 경우 이 개체는
Windows Form의 각 데이터 원본에는 단일 CurrencyManager 또는 PropertyManager 있습니다. Windows Form과 연결된 여러 데이터 원본이 있을 수 있으므로 BindingContext 사용하여 데이터 원본과 연결된 특정 CurrencyManager 검색할 수 있습니다.
메모
속성을 사용할 Item[] 때 새 속성 BindingContext 이 없는 경우 새로 BindingManagerBase 만듭니다. 반환된 개체가 의도한 목록(또는 목록)을 관리하지 못할 수 있으므로 이로 인해 약간의 혼란이 발생할 수 있습니다. 잘못된 BindingManagerBase반환을 방지하려면 메서드를 Contains 사용하여 의도한 BindingManagerBase 것이 이미 있는지 확인합니다.
또는 데이터 바인딩된 컨트롤을 포함하기 위해 컨테이너 컨트롤GroupBoxPanelTabControl을 사용하는 경우 해당 컨테이너 컨트롤 및 해당 컨트롤에 대한 컨트롤만 만들 BindingContext 수 있습니다. 그런 다음 양식의 각 부분을 자체 BindingManagerBase적으로 관리할 수 있습니다. 동일한 데이터 원본에 BindingContext 대해 여러 BindingManagerBase 개체를 만드는 방법에 대한 자세한 내용은 생성자를 참조하세요.
폼에 컨트롤을 TextBox 추가하고 데이터 세트의 테이블 열에 바인딩하면 컨트롤이 해당 폼의 열과 BindingContext 통신합니다. 따라서 해당 BindingContext데이터 연결에 대한 특정 CurrencyManager 데이터 연결에 대해 설명합니다. 해당 속성을 쿼리한 Position 경우 해당 TextBox 컨트롤의 CurrencyManager바인딩에 대한 현재 레코드를 보고합니다. 다음 코드 예제 TextBox 에서는 컨트롤이 있는 폼에 대 한 Customers 통해 데이터 세트 BindingContext 에 dataSet1 있는 테이블의 열에 바인딩 FirstName 됩니다.
TextBox1.DataBindings.Add("Text", dataSet1, "Customers.FirstName")
textBox1.DataBindings.Add("Text", dataSet1, "Customers.FirstName");
폼에 두 번째 TextBox 컨트롤(TextBox2)을 추가하고 동일한 데이터 세트의 Customers 테이블 열에 바인딩할 LastName 수 있습니다. 두 BindingContext 텍스트 상자가 동일한 데이터 세트()에 바인딩되므로 첫 번째 바인딩(TextBox1DataSet1toCustomers.FirstName)을 인식하므로 동일하게 CurrencyManager사용됩니다.
TextBox2.DataBindings.Add("Text", dataSet1, "Customers.LastName")
textBox2.DataBindings.Add("Text", dataSet1, "Customers.LastName");
다른 데이터 세트에 바인딩 TextBox2 하는 경우 두 번째 CurrencyManager데이터 세트를 BindingContext 만들고 관리합니다.
설정 DataSource 방법 및 속성에 대해 일관성을 유지하는 것이 중요합니다 DisplayMember . 그렇지 않으면 BindingContext 동일한 데이터 세트에 대해 여러 통화 관리자를 만들어 오류가 발생합니다. 다음 코드 예제에서는 속성 및 연결된 BindingContext 개체를 설정하는 몇 가지 방법을 보여 있습니다. 코드 전체에서 일관성을 유지하는 한 다음 방법 중 하나를 사용하여 속성을 설정할 수 있습니다.
ComboBox1.DataSource = DataSet1
ComboBox1.DisplayMember = "Customers.FirstName"
Me.BindingContext(dataSet1, "Customers").Position = 1
comboBox1.DataSource = DataSet1;
comboBox1.DisplayMember = "Customers.FirstName";
this.BindingContext[dataSet1, "Customers"].Position = 1;
ComboBox1.DataSource = DataSet1.Customers
ComboBox1.DisplayMember = "FirstName"
Me.BindingContext(dataSet1.Customers).Position = 1
comboBox1.DataSource = DataSet1.Customers;
comboBox1.DisplayMember = "FirstName";
this.BindingContext[dataSet1.Customers].Position = 1;
메모
대부분의 Windows Forms 애플리케이션은 BindingSource 통해 바인딩됩니다.
BindingSource 구성 요소는 a를 CurrencyManager 캡슐화하고 프로그래밍 인터페이스를 CurrencyManager 노출합니다. 바인딩에 대 한 사용 BindingSource 하는 경우 "통화"(즉, Position)를 통해 이동 하는 대신 조작 하려면에 의해 BindingSource 노출 된 멤버를 BindingContext사용 해야 합니다.
생성자
| Name | Description |
|---|---|
| BindingContext() |
BindingContext 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| IsReadOnly |
컬렉션이 읽기 전용인지 여부를 나타내는 값을 가져옵니다. |
| Item[Object, String] |
BindingManagerBase 지정된 데이터 원본 및 데이터 멤버와 연결된 값을 가져옵니다. |
| Item[Object] |
BindingManagerBase 지정된 데이터 원본과 연결된 데이터를 가져옵니다. |
메서드
이벤트
| Name | Description |
|---|---|
| CollectionChanged |
처리할 때 항상 발생 NotImplementedException 합니다. |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| ICollection.CopyTo(Array, Int32) |
컬렉션의 요소를 컬렉션 인덱스에서 시작하여 지정된 배열에 복사합니다. |
| ICollection.Count |
에서 관리하는 BindingContext총 개체 수를 CurrencyManager 가져옵니다. |
| ICollection.IsSynchronized |
컬렉션이 동기화되는지 여부를 나타내는 값을 가져옵니다. |
| ICollection.SyncRoot |
동기화(스레드 안전)에 사용할 개체를 가져옵니다. |
| IEnumerable.GetEnumerator() |
컬렉션의 열거자를 가져옵니다. |
확장명 메서드
| Name | Description |
|---|---|
| AsParallel(IEnumerable) |
쿼리의 병렬 처리를 사용하도록 설정합니다. |
| AsQueryable(IEnumerable) |
IEnumerable IQueryable변환합니다. |
| Cast<TResult>(IEnumerable) |
IEnumerable 요소를 지정된 형식으로 캐스팅합니다. |
| OfType<TResult>(IEnumerable) |
지정된 형식에 따라 IEnumerable 요소를 필터링합니다. |