This topic has not yet been rated - Rate this topic

IEditableObject Interface

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

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

public interface IEditableObject

The IEditableObject type exposes the following members.

  Name Description
Public method Supported by the XNA Framework Supported by Portable Class Library BeginEdit Begins an edit on an object.
Public method Supported by the XNA Framework Supported by Portable Class Library CancelEdit Discards changes since the last BeginEdit call.
Public method Supported by the XNA Framework Supported by Portable Class Library EndEdit Pushes 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 class Customer : IEditableObject 
	{

		struct CustomerData 
		{
			internal string id ;
			internal string firstName ;
			internal string lastName ;
		}

		private CustomersList parent;
		private CustomerData custData; 
		private CustomerData backupData; 
		private bool inTxn = false;

		// Implements IEditableObject
		void IEditableObject.BeginEdit() 
		{
			Console.WriteLine("Start BeginEdit");
			if (!inTxn) 
			{
				this.backupData = custData;
				inTxn = true;
				Console.WriteLine("BeginEdit - " + this.backupData.lastName);
			}
			Console.WriteLine("End BeginEdit");
		}

		void IEditableObject.CancelEdit() 
		{
			Console.WriteLine("Start CancelEdit");
			if (inTxn) 
			{
				this.custData = backupData;
				inTxn = false;
				Console.WriteLine("CancelEdit - " + this.custData.lastName);
			}
			Console.WriteLine("End CancelEdit");
		}

		void IEditableObject.EndEdit() 
		{
			Console.WriteLine("Start EndEdit" + this.custData.id + this.custData.lastName);
			if (inTxn) 
			{
				backupData = new CustomerData();
				inTxn = false;
				Console.WriteLine("Done EndEdit - " + this.custData.id + this.custData.lastName);
			}
			Console.WriteLine("End EndEdit");
		}

		public Customer(string ID) : base() 
		{
			this.custData = new CustomerData();
			this.custData.id = ID;
			this.custData.firstName = "";
			this.custData.lastName = "";
		}

		public string ID 
		{
			get 
			{
				return this.custData.id;
			}
		}

		public string FirstName 
		{
			get 
			{
				return this.custData.firstName;
			}
			set 
			{
				this.custData.firstName = value;
                this.OnCustomerChanged();
			}
		}

		public string LastName 
		{
			get 
			{
				return this.custData.lastName;
			}
			set 
			{
				this.custData.lastName = value;
                this.OnCustomerChanged();
			}
		}

		internal CustomersList Parent 
		{
			get 
			{
				return parent;
			}
			set 
			{
				parent = value ;
			}
		}

		private void OnCustomerChanged() 
		{
			if (!inTxn && Parent != null) 
			{
				Parent.CustomerChanged(this);
			}
		}
		
		public override string ToString() 
		{
			StringWriter sb = new StringWriter();
			sb.Write(this.FirstName);
			sb.Write(" ");
			sb.Write(this.LastName);
			return sb.ToString();
		}   
	}


.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

Portable Class Library

Supported in: Portable Class Library

Windows 8 Release Preview, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 SP2, 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.

Did you find this helpful?
(1500 characters remaining)