RejectChanges Method

Overview

The RejectChanges method reverts a row to its baseline (original) values captured by the framework. The method behaves differently depending on the current state of the row.

If the current state of the row is Detached or Unchanged then RejectChanges method does nothing.

If the current state of the row is Added, the RejectChanges method throws an exception because "reject changes" means added row needs to be removed from the table it was added to, but that action must be performed at table level (for example, IDataTable.RejectChanges).

If the current state of the row is Deleted or Modified then the RejectChanges method restores row values from the snapshot if it exists and changes the row's state to Unchanged. If no snapshot exists, it still sets state to Unchanged and clears snapshot (which is already null).

Important notes:

Declaration

/// <summary>
/// Rejects changes
/// IObservableDataRow interface implementation
/// </summary>
/// <param name="requestor">Method execution requestor</param>
public void RejectChanges(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 in Modified state
IObservableDataRow departmentObservableDataRow1 = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow1["Id"] = 1;
departmentObservableDataRow1["Name"] = "Marketing";
departmentObservableDataRow1.AcceptChanges();
departmentObservableDataRow1["Name"] = "Reception";

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

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

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 Unchanged
    DataRowState oldState = e.OldState;

    // e.NewState is Modified
    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.