CurrencyManager.SuspendBinding CurrencyManager.SuspendBinding CurrencyManager.SuspendBinding CurrencyManager.SuspendBinding Method

定义

挂起数据绑定,以防止所做的更改对绑定数据源进行更新。Suspends data binding to prevents changes from updating the bound data source.

public:
 override void SuspendBinding();
public override void SuspendBinding ();
override this.SuspendBinding : unit -> unit
Public Overrides Sub SuspendBinding ()

示例

下面的代码示例演示如何使用 SuspendBinding 方法。The following code example demonstrates how to use the SuspendBinding method.

void button3_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   try
   {
      BindingManagerBase^ myBindingManager1 = BindingContext[ myDataSet, "Customers" ];
      myBindingManager1->SuspendBinding();
   }
   catch ( Exception^ ex ) 
   {
      MessageBox::Show( ex->Source );
      MessageBox::Show( ex->Message );
   }
}
private void button3_Click(object sender, EventArgs e)
{
   try
   {
      BindingManagerBase myBindingManager1=BindingContext [myDataSet, "Customers"];
      myBindingManager1.SuspendBinding();
   }
   catch(Exception ex)
   {
      MessageBox.Show(ex.Source);
      MessageBox.Show(ex.Message);
   }
}
Private Sub button3_Click(sender As Object, e As EventArgs)
   Try
      Dim myBindingManager1 As BindingManagerBase = BindingContext(myDataSet, "Customers")
      myBindingManager1.SuspendBinding()
   Catch ex As Exception
      MessageBox.Show(ex.Source.ToString())
      MessageBox.Show(ex.Message.ToString())
   End Try
End Sub

注解

SuspendBindingResumeBinding方法允许在简单的绑定方案中暂时挂起和恢复数据绑定。The SuspendBinding and ResumeBinding methods allow the temporary suspension and resumption of data binding in a simple binding scenario. 如果用户必须在进行验证之前对数据字段进行多次编辑, 通常会挂起数据绑定。You would typically suspend data binding if the user must make several edits to data fields before validation occurs. 例如, 如果必须根据第二个字段更改一个字段, 但在验证第一个字段时将导致第二个字段出现错误。For example, if one field must be changed in accordance with a second, but where validating the first field would cause the second field to be in error.

备注

SuspendBinding在调用之前ResumeBinding , 阻止将更改应用于数据源, 但实际上不会阻止任何事件发生。SuspendBinding prevents changes from being applied to the data source until ResumeBinding is called, but does not actually prevent any events from occurring. 使用复杂数据绑定的控件 (如DataGridView控件) 根据更改事件 (例如ListChanged事件) 更新其值。Controls that use complex data binding, such as the DataGridView control, update their values based on change events, such as the ListChanged event. 因此, 调用SuspendBinding不会阻止复杂绑定控件接收事件以更新数据源。Therefore, calling SuspendBinding will not prevent complex-bound controls from receiving events to update the data source. 出于此原因, SuspendBindingResumeBinding旨在用于简单绑定TextBox控件 (如控件)。For this reason, SuspendBinding and ResumeBinding are designed for use with simple-bound controls, such as the TextBox control. 或者, 如果通过ListChanged RaiseListChangedEvents将属性设置为来false禁止显示事件, 则可以在复杂的绑定方案中使用这些方法。Alternatively, you can use these methods in a complex binding scenario if you suppress ListChanged events by setting the RaiseListChangedEvents property to false.

适用于

另请参阅