BindingContext.Item[] 속성

정의

BindingManagerBase을 가져옵니다.

오버로드

Item[Object, String]

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

Item[Object]

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

Item[Object, String]

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

public:
 property System::Windows::Forms::BindingManagerBase ^ default[System::Object ^, System::String ^] { System::Windows::Forms::BindingManagerBase ^ get(System::Object ^ dataSource, System::String ^ dataMember); };
public System.Windows.Forms.BindingManagerBase this[object dataSource, string dataMember] { get; }
public System.Windows.Forms.BindingManagerBase this[object dataSource, string? dataMember] { get; }
member this.Item(obj * string) : System.Windows.Forms.BindingManagerBase
Default Public ReadOnly Property Item(dataSource As Object, dataMember As String) As BindingManagerBase

매개 변수

dataSource
Object

특정 BindingManagerBase와 관련된 데이터 소스입니다.

dataMember
String

특정 BindingManagerBase에 대한 정보가 포함된 탐색 경로입니다.

속성 값

지정된 데이터 소스 및 데이터 멤버에 대한 BindingManagerBase입니다.

예외

데이터 소스에 지정한 dataMember가 없는 경우

예제

다음 코드 예제를 사용 Item[] 하는 방법에 설명 합니다 특정 바인딩에 대 한 검색 BindingManagerBase 합니다. 또한 에 대한 BindingManagerBase 이벤트를 처리 BindingComplete 하여 컨트롤 값 중 하나가 변경될 때 동일한 데이터 원본에 바인딩된 여러 컨트롤이 동기화된 상태로 유지되도록 하는 방법을 보여 줍니다. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 합니다 InitializeControlsAndData 폼의 생성자에서 메서드 또는 Load 이벤트 처리 메서드.

private void InitializeControlsAndData()
{
    // Initialize the controls and set location, size and 
    // other basic properties.
    this.dataGridView1 = new DataGridView();
    
    this.textBox1 = new TextBox();
    this.textBox2 = new TextBox();
    this.dataGridView1.ColumnHeadersHeightSizeMode =
        DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    this.dataGridView1.Dock = DockStyle.Top;
    this.dataGridView1.Location = new Point(0, 0);
    this.dataGridView1.Size = new Size(292, 150);
    this.textBox1.Location = new Point(132, 156);
    this.textBox1.Size = new Size(100, 20);
    this.textBox2.Location = new Point(12, 156);
    this.textBox2.Size = new Size(100, 20);
    this.ClientSize = new Size(292, 266);
    this.Controls.Add(this.textBox2);
    this.Controls.Add(this.textBox1);
    this.Controls.Add(this.dataGridView1);

    // Declare the DataSet and add a table and column.
    DataSet set1 = new DataSet();
    set1.Tables.Add("Menu");
    set1.Tables[0].Columns.Add("Beverages");

    // Add some rows to the table.
    set1.Tables[0].Rows.Add("coffee");
    set1.Tables[0].Rows.Add("tea");
    set1.Tables[0].Rows.Add("hot chocolate");
    set1.Tables[0].Rows.Add("milk");
    set1.Tables[0].Rows.Add("orange juice");

    // Add the control data bindings.
    dataGridView1.DataSource = set1;
    dataGridView1.DataMember = "Menu";
    textBox1.DataBindings.Add("Text", set1,
        "Menu.Beverages", true, DataSourceUpdateMode.OnPropertyChanged);
    textBox2.DataBindings.Add("Text", set1,
        "Menu.Beverages", true, DataSourceUpdateMode.OnPropertyChanged);

    BindingManagerBase bmb = this.BindingContext[set1, "Menu"];
    bmb.BindingComplete += new BindingCompleteEventHandler(bmb_BindingComplete);
}

private void bmb_BindingComplete(object sender, BindingCompleteEventArgs e)
{
    // Check if the data source has been updated, and that no error has occurred.
    if (e.BindingCompleteContext ==
        BindingCompleteContext.DataSourceUpdate && e.Exception == null)

        // If not, end the current edit.
        e.Binding.BindingManagerBase.EndCurrentEdit(); ;
}
Dim WithEvents bmb As BindingManagerBase

Private Sub InitializeControlsAndData() 
    ' Initialize the controls and set location, size and 
    ' other basic properties.
    Me.dataGridView1 = New DataGridView()
    
    Me.textBox1 = New TextBox()
    Me.textBox2 = New TextBox()
    Me.dataGridView1.ColumnHeadersHeightSizeMode = _
        DataGridViewColumnHeadersHeightSizeMode.AutoSize
    Me.dataGridView1.Dock = DockStyle.Top
    Me.dataGridView1.Location = New Point(0, 0)
    Me.dataGridView1.Size = New Size(292, 150)
    Me.textBox1.Location = New Point(132, 156)
    Me.textBox1.Size = New Size(100, 20)
    Me.textBox2.Location = New Point(12, 156)
    Me.textBox2.Size = New Size(100, 20)
    Me.ClientSize = New Size(292, 266)
    Me.Controls.Add(Me.textBox2)
    Me.Controls.Add(Me.textBox1)
    Me.Controls.Add(Me.dataGridView1)
    
    ' Declare the DataSet and add a table and column.
    Dim set1 As New DataSet()
    set1.Tables.Add("Menu")
    set1.Tables(0).Columns.Add("Beverages")
    
    ' Add some rows to the table.
    set1.Tables(0).Rows.Add("coffee")
    set1.Tables(0).Rows.Add("tea")
    set1.Tables(0).Rows.Add("hot chocolate")
    set1.Tables(0).Rows.Add("milk")
    set1.Tables(0).Rows.Add("orange juice")

    ' Add the control data bindings.
    dataGridView1.DataSource = set1
    dataGridView1.DataMember = "Menu"
    textBox1.DataBindings.Add("Text", set1, "Menu.Beverages", _
        True, DataSourceUpdateMode.OnPropertyChanged)
    textBox2.DataBindings.Add("Text", set1, "Menu.Beverages", _
        True, DataSourceUpdateMode.OnPropertyChanged)

    ' Get the BindingManagerBase for this binding.
    bmb = Me.BindingContext(set1, "Menu")

End Sub

Private Sub bmb_BindingComplete(ByVal sender As Object, ByVal e As BindingCompleteEventArgs) _
    Handles bmb.BindingComplete

    ' Check if the data source has been updated, and that no error has occurred.
    If e.BindingCompleteContext = BindingCompleteContext.DataSourceUpdate _
        AndAlso e.Exception Is Nothing Then

        ' If not, end the current edit.
        e.Binding.BindingManagerBase.EndCurrentEdit()
    End If
End Sub

설명

가 데이터 원본에 BindingManagerBase 여러 개체가 포함된 개체 집합 Binding 을 관리할 때 이 오버로드를 사용합니다. 예를 들어 는 개체에 DataSet 의해 연결된 여러 DataTable 개체를 DataRelation 포함할 수 있습니다. 이러한 경우 탐색 경로가 올바른 BindingManagerBase를 반환할 수 있도록 설정 BindingContext 해야 합니다.

참고

매개 변수가 BindingManagerBase유효한 경우 속성은 Item[] 항상 를 dataMember 반환합니다. 를 반환 null하지 않습니다.

Binding 가능한 데이터 원본 목록 및 컨트롤과 데이터 원본 간에 바인딩을 만드는 방법에 대한 자세한 내용은 클래스를 참조하세요.

원하는 BindingManagerBase 사용자가 목록을 관리하는 경우 탐색 경로도 목록으로 끝나야 합니다. 예를 들어 다음 C# 코드는 컨트롤을 TextBox 주문 테이블의 주문 날짜에 바인딩합니다. 탐색 경로에는 , RelationName및 가 포함됩니다.TableNameColumnName 그러나 은 BindingManagerBaseRelationName (목록으로 확인됨)만 TableName 사용하여 검색해야 합니다.

// The navigation path for a Binding ends with a property.  
textBox1.DataBindings.Add  
("Text", dataSet1, "Customers.custToOrders.OrderDate");  
// The navigation path for the BindingManagerBase ends with a list.  
BindingManagerBase bmOrders = this.BindingContext  
[dataSet1, "Customers.custToOrders"];  

BindingManagerBase반환하는 경우 와 동일한 데이터 원본을 Binding 사용하고 탐색 경로만 수정해야 합니다.

메서드를 Contains 사용하여 원하는 BindingManagerBase 가 이미 있는지 확인합니다.

추가 정보

적용 대상

Item[Object]

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

public:
 property System::Windows::Forms::BindingManagerBase ^ default[System::Object ^] { System::Windows::Forms::BindingManagerBase ^ get(System::Object ^ dataSource); };
public System.Windows.Forms.BindingManagerBase this[object dataSource] { get; }
member this.Item(obj) : System.Windows.Forms.BindingManagerBase
Default Public ReadOnly Property Item(dataSource As Object) As BindingManagerBase

매개 변수

dataSource
Object

특정 BindingManagerBase와 관련된 데이터 소스입니다.

속성 값

지정된 데이터 소스에 대한 BindingManagerBase입니다.

예제

다음 코드 예제에서는 세 BindingManagerBase 개의 개체를 DataView반환합니다. 하나는 에 대해, 하나는 에 ArrayList대해, 다른 하나는 컨트롤에 속하는 의 Binding 에 대한 DataSource 개체입니다TextBox.

void ReturnBindingManagerBase()
{
   
   // Get the BindingManagerBase for a DataView. 
   BindingManagerBase^ bmCustomers = this->BindingContext[ myDataView ];
   
   /* Get the BindingManagerBase for an ArrayList. */
   BindingManagerBase^ bmOrders = this->BindingContext[ myArrayList ];
   
   // Get the BindingManagerBase for a TextBox control.
   BindingManagerBase^ baseArray = this->BindingContext[ textBox1->DataBindings[ nullptr ]->DataSource ];
}
private void ReturnBindingManagerBase()
{
   // Get the BindingManagerBase for a DataView. 
   BindingManagerBase bmCustomers = 
   this.BindingContext [myDataView];

   /* Get the BindingManagerBase for an ArrayList. */ 
   BindingManagerBase bmOrders = 
   this.BindingContext[myArrayList];

   // Get the BindingManagerBase for a TextBox control.
   BindingManagerBase baseArray = 
   this.BindingContext[textBox1.DataBindings[0].DataSource];
}
Private Sub ReturnBindingManagerBase()
   ' Get the BindingManagerBase for a DataView. 
   Dim bmCustomers As BindingManagerBase = _
      Me.BindingContext(myDataView)

   ' Get the BindingManagerBase for an ArrayList.
   Dim bmOrders As BindingManagerBase = _
      Me.BindingContext(myArrayList)

   ' Get the BindingManagerBase for a TextBox control.
   Dim baseArray As BindingManagerBase = _
      Me.BindingContext(Text1.DataBindings(0).DataSource)
End Sub

설명

원하는 에 탐색 경로가 BindingManagerBase 필요하지 않은 경우 이 오버로드를 사용합니다. 예를 들어 가 BindingManagerBase 또는 DataTableDataSource를 로 사용하는 개체 집합 BindingArrayList 관리하는 경우 탐색 경로가 필요하지 않습니다.

참고

속성은 Item[] 항상 를 반환하고 를 BindingManagerBase반환 null하지 않습니다.

Binding 가능한 데이터 원본 목록 및 컨트롤과 데이터 원본 간에 바인딩을 만드는 방법에 대한 자세한 내용은 클래스를 참조하세요.

추가 정보

적용 대상