BindingManagerBase.EndCurrentEdit Method

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public abstract void EndCurrentEdit()

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

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft