The Code Project

By Pete2004

http://www.dotnet247.com/247reference/a.aspx?u=http://www.codeproject.com/csharp/PracticalGuideDataGrids1.asp

This is an important section to understand because the Table class maintains different states and versions of rows that can be used to provide rollback, undo and transaction logging capability. That is, this state and version information provides very powerful programmatic control over table data and UI strategies.

Before discussing row states and versions there are Table and Row methods that need to be defined:

Table Method | Description
`AcceptChanges()` | Accepts all row changes to the table. Changes can be accepted to individual rows when the DataRow `AcceptChanges(``)` method is called.
`RejectChanges()` | Rejects all row changes to the table that have taken place since the last call to the Table or DataRow `AcceptChanges(``)`.
`GetChanges()` | Returns a table containing all rows that have been modified. This is particular useful when building transaction logs to satisfy government and corporate regulations, such as CFR21-11. Note: If the Table `AcceptChanges` is called prior to `GetChanges` then there will be no changes and the return value is null.

Rows Method | Description
`Add()` | Adds a row to the rows collection
`InsertAt()` | Inserts a row at a specific position in the rows collection
`RemoveAt()` | Removes a row at an index from the rows collection
`AcceptChanges()` | Accepts all changes to the row including changes to the individual cells including adding and deleting the row to and from the table respectively.
`RejectChanges()` | Rejects changes to the row restoring the original values
`BeginEdit()` | Begins a row editing session
`CancelEdit()` | Cancels a row editing session and restores all previous values
`EndEdit()` | Ends a row editing session

There are four different versions of Row Collections that are automatically maintained by the Table’s object that provides extensive programmatic control over edits, deletes and inserts.

DataRowVersion | Description
`Current` | This version contains the current set of all values contained in each table row. The current set and the default set are identical during modifying a row without calling `BeginEdit()` after `AcceptChanges()` is called.
`Default` | The Default rows collection contains all of the changes. Each time a new row is created the new row is initialized to the default column values. Each time a cell value within a row is modified, the modification will be reflected in this table.
`Proposed` | This version as its name implies contains only rows that have proposed changes where they are only present during a call to `BeginEdit(``)`. When `EndEdit(``)` is called the proposed changes are reflected in the Current `DataRow`, in the Original DataRow and proposed DataRow is deleted. When the `CancelEdit` is called, the proposed DataRow is deleted and the Default DataRow is changed back to the Current `DataRow` values.
`Original` | The Original Rows collection is updated each time `AcceptChanges(``)` is called. These values are used when `RejectChanges(``)` and `CancelEdit()` are called to return the values back to the state before any changes occurred since the last call to `AcceptChanges()`.

RowState | Description
`Added` | The row is marked as Added when a row is added or inserted to the Rows Collection and before an `AcceptChanges(``)` method is called.
`Deleted` | After `AcceptChanges()` is called the row is marked as Deleted when any of the following is performed: `dr.Delete()` `dt.Rows.RemoveAt(index)` `dt.Rows.Remove(dr)`
`Detached` | Before `AcceptChanges()` is called the row is marked as Detached when any of the following is performed: `dr.Delete()` `dt.Rows.RemoveAt(index)` `dt.Rows.Remove(dr)`
`Modified` | After `AcceptChanges(``)` is called any row cell value that is changed causes the row to be marked as Modified.
`Unchanged` | After `AcceptChanges(``)` is called the row or all rows are marked as Unchanged depending upon whether it is a DataRow `AcceptChanges()` call or Table `AcceptChanges()` call.

#### Return Values From DataRow.RowState()

Member name | Description | Value
Added Supported by the .NET Compact Framework. | The row has been added to a DataRowCollection, and AcceptChanges has not been called. | 4
Deleted Supported by the .NET Compact Framework. | The row was deleted using the Delete method of the DataRow. | 8
Detached Supported by the .NET Compact Framework. | The row has been created but is not part of any DataRowCollection. A DataRow is in this state immediately after it has been created and before it is added to a collection, or if it has been removed from a collection. | 1
Modified Supported by the .NET Compact Framework. | The row has been modified and AcceptChanges has not been called. | 16
Unchanged Supported by the .NET Compact Framework. | The row has not changed since AcceptChanges was last called. | 2

####