CurrencyManager.CancelCurrentEdit 方法

取消当前编辑操作。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Overrides Sub CancelCurrentEdit
用法
Dim instance As CurrencyManager

instance.CancelCurrentEdit
public override void CancelCurrentEdit ()
public:
virtual void CancelCurrentEdit () override
public void CancelCurrentEdit ()
public override function CancelCurrentEdit ()

备注

仅当数据源包含的对象实现 IEditableObject 接口时,才支持该方法。如果数据源中包含的对象不实现 IEditableObject 接口,则将不放弃对数据所做的更改。

提示

此属性旨在由复杂数据绑定控件(如 DataGrid 控件)用来取消编辑。例如,用户按下 Esc 键时,会对 DataGridCurrencyManager 调用 CancelCurrentEdit 方法。除非要创建的控件需要此功能,否则不应使用此方法。而应使用 DataRowView 类的 CancelEdit 方法。

示例

下面的代码示例在用户按下 Esc 键时使用 CancelCurrentEdit

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 'dataGrid1_KeyUp
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:
   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!" );
      }
   }
protected void dataGrid1_KeyUp( Object sender, 
    System.Windows.Forms.KeyEventArgs e)
{
    if (e.get_KeyCode().Equals(System.Windows.Forms.Keys.Escape)) {
        // Escape key pressed.
        CurrencyManager gridCurrencyManager = 
            (CurrencyManager)(this.get_BindingContext().
            get_Item(dataGrid1.get_DataSource(),
            dataGrid1.get_DataMember()));
        gridCurrencyManager.CancelCurrentEdit();
        MessageBox.Show("Escape!");
    }
} //dataGrid1_KeyUp
protected function dataGrid1_KeyUp
(sender, e : System.Windows.Forms.KeyEventArgs)
{
   if(e.KeyCode == System.Windows.Forms.Keys.Escape){
      // Escape key pressed.
      var gridCurrencyManager : CurrencyManager  = 
      CurrencyManager(this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]);
      gridCurrencyManager.CancelCurrentEdit();
      MessageBox.Show("Escape!");
   }
}

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

CurrencyManager 类
CurrencyManager 成员
System.Windows.Forms 命名空间
EndCurrentEdit