AcceptChanges Method

Overview

The AcceptChanges method accepts the row current values as the new baseline and sets the row’s state to Unchanged (when applicable). The baseline is later used by RejectChanges to restore values when changes are rejected.

If the current state of the row is Detached or Unchanged, the AcceptChanges method does nothing.

If the current state of the row is Deleted then AcceptChanges method throws an exception because accepting changes means the deleted row must be removed from the table it belongs to, but that action can be done at table level only.

If the current state of the row is Added or Modified then the AcceptChanges method changes the row's state to Unchanged. For Added and Modified rows, AcceptChanges() discards any stored original-value snapshot and makes current values the baseline.

Important notes:

Declaration

/// <summary>
/// Accepts changes on the inner data row and raises RowStateChanged if the row state changes.
/// Note: Deleted rows should typically be handled at table level because accepting a deletion may remove the row from a table.
/// IObservableDataRow interface implementation
/// </summary>
/// <param name="requestor">Object which requests update</param>
public void AcceptChanges(object? requestor = null)

Namespace and Assembly

Namespace: PocoDataSet.ObservableData
Assembly: PocoDataSet.ObservableData.dll

Usage Example

// 1. Create observable data set
IObservableDataSet observableDataSet = new ObservableDataSet();

// 2. Create Department observable table
IObservableDataTable departmentObservableDataTable = observableDataSet.AddNewTable("Department");
departmentObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentObservableDataTable.AddColumn("Name", DataTypeNames.STRING);

// 3. Add observable data row to Department observable table
IObservableDataRow departmentObservableDataRow1 = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow1["Id"] = 1;
departmentObservableDataRow1["Name"] = "Marketing";

// 4. Subscribe to PropertyChanged and RowStateChanged events of the observable data row
departmentObservableDataRow1.PropertyChanged += DepartmentObservableDataRow1_PropertyChanged;
departmentObservableDataRow1.RowStateChanged += DepartmentObservableDataRow1_RowStateChanged;

// 5. Call AcceptChanges method of an observable data row and observe that all events were raised and handled
departmentObservableDataRow1.AcceptChanges();

private void DepartmentObservableDataRow1_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
    // propertyName = "DataRowState"
    string propertyName = e.PropertyName;
}

private void DepartmentObservableDataRow1_RowStateChanged(object? sender, RowStateChangedEventArgs e)
{
    // e.OldState is Added
    DataRowState oldState = e.OldState;

    // e.NewState is Unchanged
    DataRowState newState = e.NewState;
}

 

Table of Content POCO DataSet API References ObservablePOCO DataSet Types ObservableDataRow Members

 


Business Process Programming in .Net
© 2004–2026 Laskarzhevsky Software Inc.
Unless otherwise noted, the content of this website is licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).
Code examples are provided under the MIT License.
You are free to share and adapt the material provided that appropriate credit is given and any modifications are clearly indicated.
The information provided on this website is for educational purposes only.
The author and publisher make no warranties regarding the completeness or suitability of the information and are not responsible for any damages resulting from its use.