BindingCompleteEventArgs.Binding 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得與這次發生的 BindingComplete 事件相關聯的繫結。
public:
property System::Windows::Forms::Binding ^ Binding { System::Windows::Forms::Binding ^ get(); };
public System.Windows.Forms.Binding Binding { get; }
public System.Windows.Forms.Binding? Binding { get; }
member this.Binding : System.Windows.Forms.Binding
Public ReadOnly Property Binding As Binding
屬性值
與這個 Binding 相關聯的 BindingCompleteEventArgs。
範例
下列程式碼範例示範如何處理 BindingComplete 事件,並使用 BindingCompleteEventArgs ,以確保在變更其中一個控制項值時,系結至相同資料來源的多個控制項仍保持同步。 若要執行此範例,請將程式碼貼到 Windows Form 中,並從表單的建構函式或 Load 事件處理方法呼叫 InitializeControlsAndData
方法。
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
備註
Binding也可能與 BindingComplete 繼承自 BindingManagerBase 之 BindingSource 類別的事件相關聯。