CurrencyManager.CancelCurrentEdit 方法

定义

取消当前的编辑操作。Cancels the current edit operation.

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

示例

下面的代码示例在用户CancelCurrentEdit按 ESC 键时使用。The following code example uses the CancelCurrentEdit when the user presses the ESC key.

private:
   void dataGrid1_KeyUp( Object^ /*sender*/, System::Windows::Forms::KeyEventArgs^ e )
   {
      if ( e->KeyCode == System::Windows::Forms::Keys::Escape )
      {
         
         // Escape key pressed.
         CurrencyManager^ gridCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[dataGrid1->DataSource, dataGrid1->DataMember]);
         gridCurrencyManager->CancelCurrentEdit();
         MessageBox::Show( "Escape!" );
      }
   }

private void dataGrid1_KeyUp
(object sender, System.Windows.Forms.KeyEventArgs e)
{
   if(e.KeyCode == System.Windows.Forms.Keys.Escape){
      // Escape key pressed.
      CurrencyManager gridCurrencyManager = 
      (CurrencyManager)this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember];
      gridCurrencyManager.CancelCurrentEdit();
      MessageBox.Show("Escape!");
   }
}

Private Sub dataGrid1_KeyUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)

    If e.KeyCode = System.Windows.Forms.Keys.Escape Then
        ' Escape key pressed.
        Dim gridCurrencyManager As CurrencyManager = _
            CType(Me.BindingContext(dataGrid1.DataSource, _
            dataGrid1.DataMember), CurrencyManager)

        gridCurrencyManager.CancelCurrentEdit()
        MessageBox.Show("Escape!")
    End If
End Sub

注解

仅当数据源包含的对象实现IEditableObject接口时, 才支持此方法。This method is supported only if the objects contained by the data source implement the IEditableObject interface. 如果数据源中包含的对象未实现IEditableObject接口, 则不会丢弃对数据所做的更改。If the objects contained within the data source do not implement the IEditableObject interface, changes made to the data will not be discarded.

备注

此属性旨在供复杂数据绑定控件 (如DataGrid控件) 用来取消编辑。This property was designed to be used by complex data-bound controls, such as the DataGrid control, to cancel edits. 例如, 当用户按 ESC 键时, CancelCurrentEdit将对的调用CurrencyManager DataGrid方法。For example, when the user presses the ESC key, the CancelCurrentEdit method is called on the CurrencyManager for the DataGrid. 除非要创建需要此相同功能的控件, 否则不应使用此方法。Unless you are creating a control that requires this same functionality, you should not use this method. 而应使用CancelEdit DataRowView类的方法。Instead, use the CancelEdit method of the DataRowView class.

适用于

另请参阅