Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

BindingManagerBase.CancelCurrentEdit Method

When overridden in a derived class, cancels the current edit.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public abstract void CancelCurrentEdit ()
public abstract void CancelCurrentEdit ()
public abstract function CancelCurrentEdit ()
Not applicable.

This method is supported only if the data source implements the IEditableObject interface. If the object does not implement the IEditableObject interface, changes made to the data will not be discarded.

Calling the CancelCurrentEdit method causes the Format event to occur.

The following code example demonstrates both the CancelCurrentEdit and the EndCurrentEdit methods. When you call the CancelCurrentEdit methods, changes made to the data are discarded. When you call the EndCurrentEdit method, the changes are kept.

private void CancelEdit()
{
    // Gets the CurrencyManager which is returned when the 
    // data source is a DataView.
    BindingManagerBase myMgr = 
        (CurrencyManager) BindingContext[myDataView]; 

    // Gets the current row and changes a value. Then cancels the 
    // edit and thereby discards the changes.
    DataRowView tempRowView = (DataRowView) myMgr.Current;
    Console.WriteLine("Original: {0}", tempRowView["myCol"]);
    tempRowView["myCol"] = "These changes will be discarded";
    Console.WriteLine("Edit: {0}", tempRowView["myCol"]);
    myMgr.CancelCurrentEdit();
    Console.WriteLine("After CanceCurrentlEdit: {0}", 
        tempRowView["myCol"]);
}

private void EndEdit()
{
    // Gets the CurrencyManager which is returned when the 
    // data source is a DataView.
    BindingManagerBase myMgr = 
        (CurrencyManager) BindingContext[myDataView];

    // Gets the current row and changes a value. Then ends the 
    // edit and thereby keeps the changes.
    DataRowView tempRowView = (DataRowView) myMgr.Current;
    Console.WriteLine("Original: {0}", tempRowView["myCol"]);
    tempRowView["myCol"] = "These changes will be kept";
    Console.WriteLine("Edit: {0}", tempRowView["myCol"]);
    myMgr.EndCurrentEdit();
    Console.WriteLine("After EndCurrentEdit: {0}", 
        tempRowView["myCol"]);
}


private void CancelEdit()
{
    // Gets the CurrencyManager which is returned when the 
    // data source is a DataView.
    BindingManagerBase myMgr = 
        (CurrencyManager)(get_BindingContext().get_Item(myDataView));

    // Gets the current row and changes a value. Then cancels the 
    // edit and thereby discards the changes.
    DataRowView tempRowView = (DataRowView)(myMgr.get_Current());
    
    Console.WriteLine("Original: {0}", tempRowView.get_Item("myCol"));
    tempRowView.set_Item("myCol", "These changes will be discarded");
    Console.WriteLine("Edit: {0}", tempRowView.get_Item("myCol"));
    myMgr.CancelCurrentEdit();
    Console.WriteLine("After CanceCurrentlEdit: {0}", 
        tempRowView.get_Item("myCol"));
} //CancelEdit

private void EndEdit()
{
    // Gets the CurrencyManager which is returned when the 
    // data source is a DataView.
    BindingManagerBase myMgr = 
        (CurrencyManager)(get_BindingContext().get_Item(myDataView));

    // Gets the current row and changes a value. Then ends the 
    // edit and thereby keeps the changes.
    DataRowView tempRowView = (DataRowView)(myMgr.get_Current());
    Console.WriteLine("Original: {0}", tempRowView.get_Item("myCol"));
    tempRowView.set_Item("myCol", "These changes will be kept");
    Console.WriteLine("Edit: {0}", tempRowView.get_Item("myCol"));
    myMgr.EndCurrentEdit();
    Console.WriteLine("After EndCurrentEdit: {0}", 
        tempRowView.get_Item("myCol"));
} //EndEdit

Windows 98, Windows Server 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

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.