BindingManagerBase.BindingComplete 이벤트

정의

데이터 바인딩 작업이 완료되면 발생합니다.Occurs at the completion of a data-binding operation.

public:
 event System::Windows::Forms::BindingCompleteEventHandler ^ BindingComplete;
public event System.Windows.Forms.BindingCompleteEventHandler BindingComplete;
member this.BindingComplete : System.Windows.Forms.BindingCompleteEventHandler 
Public Custom Event BindingComplete As BindingCompleteEventHandler 

이벤트 유형

BindingCompleteEventHandler

예제

다음 코드 예제에서는 이벤트를 처리 하 BindingComplete 고, 컨트롤 값 중 하나가 변경 될 때 동일한 데이터 소스에 바인딩된 여러 컨트롤이 동기화 된 상태를 유지 하는지 확인 하는 방법을 보여 줍니다.The following code example demonstrates how to handle the BindingComplete event and ensure multiple controls bound to the same data source remain synchronized when one of the control values is changed. 이 예제를 실행 하려면 호출을 Windows Form에 코드를 붙여넣은 합니다 InitializeControlsAndData 폼의 생성자에서 메서드 또는 Load 이벤트 처리 메서드.To run this example, paste the code into a Windows Form and call the InitializeControlsAndData method from the form's constructor or Load event-handling method.

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

설명

BindingComplete 이벤트는 다음을 포함할 수 있는 데이터 바인딩 작업이 완료 된 후에 발생 합니다.The BindingComplete event occurs after the completion of a data-binding operation, which may include the following:

  • 데이터 소스에서 바인딩된 컨트롤의 속성에 정보를 푸시합니다.Pushing information from the data source into the property of its bound control.

  • 바인딩된 컨트롤에서 연결 된 데이터 소스로 정보 가져오기Pulling information from a bound control into its associated data source.

이 이벤트는 바인딩 작업의 완료 상태에 관계 없이 발생 하지만 BindingCompleteState BindingCompleteEventArgs 이벤트와 연결 된 매개 변수의 속성을 검사 하 여이 상태를 확인할 수 있습니다.Note that this event is raised regardless of the completion status of the binding operation, although this status can be determined by examining the BindingCompleteState property of the BindingCompleteEventArgs parameter associated with the event. BindingCompleteEventArgs 오류 및 예외 정보를 포함할 수도 있습니다.BindingCompleteEventArgs may also contain error and exception information. 예를 들어 데이터 소스에서 컨트롤로 null 값을 푸시하는 바인딩 작업은 DateTimePicker 가 일 수 없으므로 예외를 생성 DateTime null 합니다.For example, a binding operation that attempts to push a null value from a data source into a DateTimePicker control will generate an exception, since a DateTime cannot be null. 이 경우 바인딩 작업이 성공적으로 완료 되지 않은 경우에도 BindingComplete 이벤트가 발생 하 고 이벤트에 실패 한 바인딩 시도에 대 한 정보가 포함 됩니다.In this case, although the binding operation does not successfully complete, the BindingComplete event will be raised, and the event will contain information on the failed binding attempt.

적용 대상

추가 정보