System.ComponentModel.IEditableObject Interface

Assembly: System.dll
Namespace: System.ComponentModel
Summary
Provides functionality to commit or rollback changes to an object that is used as a data source.
C# Syntax:
public interface IEditableObject
Remarks
This interface is typically used to capture the IEditableObject.BeginEdit, IEditableObject.EndEdit, and IEditableObject.CancelEdit semantics of a DataRowView.
Example
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 System.ComponentModel.IBindingList (not supported on the shared source CLI) 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;
			}
		}
             
		public string LastName 
		{
			get 
			{
				return this.custData.lastName;
			}
			set 
			{
				this.custData.lastName = value;
			}
		}
       
		internal CustomersList Parent 
		{
			get 
			{
				return parent;
			}
			set 
			{
				parent = value ;
			}
		}

		private void OnCustomerChanged() 
		{
			if (!inTxn && Parent != null) 
			{
				Parent.CustomerChanged(this);
			}
		}

    
See also:
System.ComponentModel Namespace

System.ComponentModel.IEditableObject Member List:

Public Methods
BeginEdit Begins an edit on an object.
CancelEdit Discards changes since the last IEditableObject.BeginEdit call.
EndEdit Pushes changes since the last IEditableObject.BeginEdit or IBindingList.AddNew call into the underlying object.

System.ComponentModel.IEditableObject Member Details

Method: BeginEdit()
Summary
Begins an edit on an object.
C# Syntax:
void BeginEdit();
Remarks
This method is typically used to capture the IEditableObject.BeginEdit semantics of a DataRowView.

If IEditableObject.BeginEdit is called on an object that is already being edited, the second and subsequent calls are ignored.



Notes to implementors: An object implementing this interface needs to store updates after IEditableObject.BeginEdit in such a way that they can be discarded if IEditableObject.CancelEdit is called.

Return to top


Method: CancelEdit()
Summary
Discards changes since the last IEditableObject.BeginEdit call.
C# Syntax:
void CancelEdit();
Remarks
This method is typically used to capture the IEditableObject.CancelEdit semantics of a DataRowView.

This method will be ignored if called on an object that is not being edited.



Note If the owning list implements System.ComponentModel.IBindingList (not supported on the shared source CLI) , calling IEditableObject.CancelEdit on an object created using IBindingList.AddNew discards the object.

Return to top


Method: EndEdit()
Summary
Pushes changes since the last IEditableObject.BeginEdit or IBindingList.AddNew call into the underlying object.
C# Syntax:
void EndEdit();
Remarks
This method is typically used to capture the IEditableObject.EndEdit semantics of a DataRowView.

This method will be ignored if called on an object that is not being edited.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.