This documentation is archived and is not being maintained.

CurrencyManager.CancelCurrentEdit Method

Cancels the current edit operation.

[Visual Basic]
Overrides Public Sub CancelCurrentEdit()
[C#]
public override void CancelCurrentEdit();
[C++]
public: void CancelCurrentEdit();
[JScript]
public override function CancelCurrentEdit();

Remarks

This method is supported only if the objects contained by the data source implement the IEditableObject interface. If the objects contained within the data source do not implement the IEditableObject interface, changes made to the data will not be discarded.

Note   This property was designed to be used by complex-bound controls, such as the DataGrid control, to cancel edits. For example, when the Esc key is pressed, the CancelCurrentEdit method is called on the CurrencyManager for the DataGrid. Unless you are creating a control that requires this same functionality, it is not recommended that you use this method. Instead, use the DataRowView class's CancelEdit.

Example

The following example uses the CancelCurrentEdit when the user presses the escape key.

[Visual Basic] 
Protected Sub dataGrid1_KeyUp(sender As Object, _
    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

[C#] 
protected 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!");
   }
}


[C++] 
protected:
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->get_Item(dataGrid1->DataSource, dataGrid1->DataMember));
      gridCurrencyManager->CancelCurrentEdit();
      MessageBox::Show(S"Escape!");
   }
}


[JScript] 
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!");
   }
}

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

CurrencyManager Class | CurrencyManager Members | System.Windows.Forms Namespace | EndCurrentEdit

Show: