BindingContext 클래스

정의

Control 클래스에서 상속되는 모든 개체에 대해 BindingManagerBase 개체의 컬렉션을 관리합니다.

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 및 4 Binding 개의 컨트롤)을 DateTimePicker 여러 데이터 원본에 바인딩하는 4개의 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[] 반환 형식은 또는 PropertyManager입니다CurrencyManager. 데이터 원본이 개체 목록 대신 단일 속성만 반환할 수 있는 개체인 경우 는 Type 입니다 PropertyManager. 예를 들어 를 데이터 원본으로 지정 TextBox 하면 가 PropertyManager 반환됩니다. 반면에 데이터 원본이 또는 IBindingList를 구현 IList 하는 개체인 경우 가 CurrencyManager 반환됩니다.

Windows Form의 각 데이터 원본에 대해 단일 CurrencyManager 또는 PropertyManager가 있습니다. Windows Form BindingContext 과 연결된 여러 데이터 원본이 있을 수 있으므로 을 사용하면 데이터 원본과 연결된 특정 CurrencyManager 항목을 검색할 수 있습니다.

참고

사용 하는 경우는 Item[] 속성이 BindingContext 없는 경우 새로 BindingManagerBase 만듭니다. 반환된 개체가 의도한 목록(또는 목록)을 관리하지 못할 수 있으므로 이로 인해 약간의 혼란이 발생할 수 있습니다. 잘못된 BindingManagerBase를 반환하지 않도록 하려면 메서드를 Contains 사용하여 의도한 BindingManagerBase 가 이미 있는지 확인합니다.

, Panel또는 TabControl와 같은 컨테이너 컨트롤을 GroupBox사용하여 데이터 바인딩된 컨트롤을 포함하는 경우 해당 컨테이너 컨트롤 및 해당 컨트롤에 대한 를 만들 BindingContext 수 있습니다. 그런 다음 양식의 각 부분을 자체 BindingManagerBase으로 관리할 수 있습니다. 동일한 데이터 원본에 BindingContext 대해 여러 BindingManagerBase 개체를 만드는 방법에 대한 자세한 내용은 생성자를 참조하세요.

TextBox 컨트롤을 폼에 추가하고 데이터 세트의 테이블 열에 바인딩하면 컨트롤은 해당 폼의 BindingContext와 통신합니다. 은 BindingContext해당 데이터 연결에 대한 특정 CurrencyManager 에 대해 설명합니다. 의 속성을 쿼리 Position 한 경우 해당 컨트롤의 CurrencyManager바인딩에 대한 현재 레코드를 TextBox 보고합니다. 다음 코드 예제에서는 TextBox 컨트롤이 dataSet1 데이터 세트의 Customers 테이블에 있는 FirstName 열을 통해 BindingContext에 바인딩됩니다.

TextBox1.DataBindings.Add("Text", dataSet1, "Customers.FirstName")  
textBox1.DataBindings.Add("Text", dataSet1, "Customers.FirstName");  
textBox1->DataBindings->Add("Text", dataSet1, "Customers.FirstName");  

두 번째 TextBox 컨트롤(TextBox2)을 폼에 추가하고 동일한 데이터 세트의 Customers 데이블의 LastName 열에 바인딩할 수 있습니다. BindingContext은 첫 번째 바인딩(Customers.FirstName에서 TextBox1)을 인식하므로 두 텍스트 상자가 동일한 데이터 세트(DataSet1)에 바인딩되므로 동일한 CurrencyManager를 사용합니다.

TextBox2.DataBindings.Add("Text", dataSet1, "Customers.LastName")  
textBox2.DataBindings.Add("Text", dataSet1, "Customers.LastName");  
textBox2->DataBindings->Add("Text", dataSet1, "Customers.LastName");  

TextBox2을 다른 데이터 세트에 바인딩하면 BindingContext가 두 번째 CurrencyManager을 만들고 관리합니다.

DataSourceDisplayMember 속성을 설정하는 방법에 대해 일관성을 유지하는 것이 중요합니다. 그렇지 않으면 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;  
comboBox1->DisplayMember = "Customers.FirstName";  
this->BindingContext->get_Item(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;  
comboBox1->DataSource = dataSet1->Customers;  
comboBox1->DisplayMember = "FirstName";  
this->BindingContext->get_Item(dataSet1->Customers)->Position = 1;  

참고

대부분의 Windows Forms 애플리케이션을 통해 바인딩하는 BindingSource합니다. BindingSource 구성 요소는 를 캡슐화 CurrencyManager 하고 프로그래밍 인터페이스를 CurrencyManager 노출합니다. 바인딩에 를 사용하는 BindingSource 경우 에서 노출하는 BindingSource 멤버를 사용하여 를 통과BindingContext하지 않고 "currency"(즉, Position)를 조작해야 합니다.

생성자

BindingContext()

BindingContext 클래스의 새 인스턴스를 초기화합니다.

속성

IsReadOnly

컬렉션이 읽기 전용인지를 나타내는 값을 가져옵니다.

Item[Object, String]

지정된 데이터 소스 및 데이터 멤버와 관련된 BindingManagerBase를 가져옵니다.

Item[Object]

지정된 데이터 소스와 연결된 BindingManagerBase를 가져옵니다.

메서드

Add(Object, BindingManagerBase)

특정 데이터 소스와 연관된 BindingManagerBase를 컬렉션에 추가합니다.

AddCore(Object, BindingManagerBase)

특정 데이터 소스와 연관된 BindingManagerBase를 컬렉션에 추가합니다.

Clear()

BindingManagerBase 개체의 컬렉션을 지웁니다.

ClearCore()

컬렉션을 지웁니다.

Contains(Object)

BindingContext에 지정한 데이터 소스와 관련된 BindingManagerBase가 포함되어 있는지 여부를 나타내는 값을 가져옵니다.

Contains(Object, String)

BindingContext에 지정한 데이터 소스 및 데이터 멤버와 관련된 BindingManagerBase가 포함되어 있는지 여부를 나타내는 값을 가져옵니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnCollectionChanged(CollectionChangeEventArgs)

CollectionChanged 이벤트를 발생시킵니다.

Remove(Object)

지정된 데이터 소스와 관련된 BindingManagerBase를 삭제합니다.

RemoveCore(Object)

지정된 데이터 소스와 관련된 BindingManagerBase를 제거합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
UpdateBinding(BindingContext, Binding)

Binding을 새 BindingContext와 연결합니다.

이벤트

CollectionChanged

처리될 때 항상 NotImplementedException을 발생시킵니다.

명시적 인터페이스 구현

ICollection.CopyTo(Array, Int32)

컬렉션 인덱스부터 컬렉션의 요소를 지정한 배열에 복사합니다.

ICollection.Count

CurrencyManager가 관리하는 전체 BindingContext 개체의 수를 가져옵니다.

ICollection.IsSynchronized

컬렉션이 동기화되는지를 나타내는 값을 가져옵니다.

ICollection.SyncRoot

동기화(스레드로부터의 안전성)에 사용할 개체를 가져옵니다.

IEnumerable.GetEnumerator()

컬렉션의 열거자를 가져옵니다.

확장 메서드

Cast<TResult>(IEnumerable)

IEnumerable의 요소를 지정된 형식으로 캐스팅합니다.

OfType<TResult>(IEnumerable)

지정된 형식에 따라 IEnumerable의 요소를 필터링합니다.

AsParallel(IEnumerable)

쿼리를 병렬화할 수 있도록 합니다.

AsQueryable(IEnumerable)

IEnumerableIQueryable로 변환합니다.

적용 대상

추가 정보