IEditableObject Interface

Provides functionality to commit or rollback changes to an object that is used as a data source.

Namespace:  System.ComponentModel
Assemblies:   System.ComponentModel (in System.ComponentModel.dll)
  System (in System.dll)

public interface class IEditableObject

The IEditableObject type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryBeginEditBegins an edit on an object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryCancelEditDiscards changes since the last BeginEdit call.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEndEditPushes changes since the last BeginEdit or IBindingList::AddNew call into the underlying object.
Top

This interface is typically used to capture the BeginEdit, EndEdit, and CancelEdit semantics of a DataRowView.

The following sample provides a simple implementation of the IEditableObject interface. The Customer class stores customer information and can be used as a collection for a customer database. This sample assumes that you have used the CustomerList class that can be found in sample in the IBindingList class.

   public ref class Customer: public IEditableObject
   {
   private:
      ref struct CustomerData
      {
      internal:
         String^ id;
         String^ firstName;
         String^ lastName;
      };

   internal:
      CustomersList^ parent;
      CustomerData^ custData;
      CustomerData^ backupData;
      bool inTxn;

      // Implements IEditableObject 
   public:
      virtual void BeginEdit()
      {
         Console::WriteLine( "Start BeginEdit" );
         if (  !inTxn )
         {
            this->backupData = custData;
            inTxn = true;
            Console::WriteLine( "BeginEdit - {0}", this->backupData->lastName );
         }

         Console::WriteLine( "End BeginEdit" );
      }

      virtual void CancelEdit()
      {
         Console::WriteLine( "Start CancelEdit" );
         if ( inTxn )
         {
            this->custData = backupData;
            inTxn = false;
            Console::WriteLine( "CancelEdit - {0}", this->custData->lastName );
         }

         Console::WriteLine( "End CancelEdit" );
      }

      virtual void EndEdit()
      {
         Console::WriteLine( "Start EndEdit{0}{1}", this->custData->id, this->custData->lastName );
         if ( inTxn )
         {
            backupData = gcnew CustomerData;
            inTxn = false;
            Console::WriteLine( "Done EndEdit - {0}{1}", this->custData->id, this->custData->lastName );
         }

         Console::WriteLine( "End EndEdit" );
      }


   public:

      Customer( String^ ID )
      {
         this->custData = gcnew CustomerData;
         this->custData->id = ID;
         this->custData->firstName = "";
         this->custData->lastName = "";
         inTxn = false;
      }

      property String^ ID 
      {
         String^ get()
         {
            return this->custData->id;
         }

      }

      property String^ FirstName 
      {
         String^ get()
         {
            return this->custData->firstName;
         }

         void set( String^ value )
         {
            this->custData->firstName = value;
			this->OnCustomerChanged();
         }

      }

      property String^ LastName 
      {
         String^ get()
         {
            return this->custData->lastName;
         }

         void set( String^ value )
         {
            this->custData->lastName = value;
			this->OnCustomerChanged();
         }

      }

   internal:

      property CustomersList^ Parent 
      {
         CustomersList^ get()
         {
            return parent;
         }

         void set( CustomersList^ value )
         {
            parent = value;
         }

      }

	  void OnCustomerChanged()
	  {
         if (!inTxn && Parent != nullptr)
         {
			 Parent->CustomerChanged(this);
		 }
	  }

   public:
      virtual String^ ToString() override
      {
         StringWriter^ sb = gcnew StringWriter;
         sb->Write( this->FirstName );
         sb->Write( " " );
         sb->Write( this->LastName );
         return sb->ToString();
      }
   };

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft