CurrencyManager.CancelCurrentEdit 方法

定义

取消当前的编辑操作。

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

示例

下面的代码示例使用 CancelCurrentEdit 当用户按下 ESC 键时。

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 接口时,才支持此方法。 如果数据源中包含的对象未实现 IEditableObject 接口,则不会放弃对数据所做的更改。

备注

此属性旨在由复杂的数据绑定控件(如 DataGrid 控件)用来取消编辑。 For example, when the user presses the ESC key, the CancelCurrentEdit method is called on the CurrencyManager for the DataGrid. 除非创建需要此功能的控件,否则不应使用此方法。 请改用 CancelEdit 类的方法 DataRowView

适用于

另请参阅