RejectChanges Method
The RejectChanges method rejects all pending changes in a table and reverts the table to the last accepted state.
This method uses state-aware logic:
it removes newly added rows from the table, and it reverts deleted or modified rows
back to their original values and Unchanged state.
/// <summary>
/// Rejects changes for an observable data table in an observable-aware way.
/// Added (and Detached) rows are removed from the observable table (raising RowsRemoved).
/// Modified and Deleted rows are reverted and RowStateChanged is raised.
/// </summary>
/// <param name="observableDataTable">Observable data table</param>
public static void RejectChanges(this IObservableDataTable? dataTable)
Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll
dataTable is null, returns immediately.Rows.Count - 1 down to 0 so that removals do not affect remaining indices.
Added or Detached - removes the row from the table via RemoveRowAt(index).
This discards new rows that were never part of the accepted baseline.
Deleted or Modified - calls IDataRow.RejectChanges() to restore original values
and row state.
Unchanged - no action is taken.
// 1. Create observable data set
IObservableDataSet observableDataSet = new ObservableDataSet();
// 2. Create Department observable table with rows in different states
IObservableDataTable departmentObservableDataTable = observableDataSet.AddNewTable("Department");
departmentObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
departmentObservableDataTable.AddColumn("Name", DataTypeNames.STRING);
// Row in Added state
IObservableDataRow departmentObservableDataRow1 = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow1["Id"] = 1;
departmentObservableDataRow1["Name"] = "Reception";
// Row in Deleted state
IObservableDataRow departmentObservableDataRow2 = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow2["Id"] = 2;
departmentObservableDataRow2["Name"] = "Sales";
departmentObservableDataRow2.AcceptChanges();
departmentObservableDataRow2.Delete();
// Row in Modified state
IObservableDataRow departmentObservableDataRow3 = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow3["Id"] = 3;
departmentObservableDataRow3["Name"] = "Emergency";
departmentObservableDataRow3.AcceptChanges();
departmentObservableDataRow3["Name"] = "Finance";
// 3. Reject changes
observableDataSet.RejectChanges();
// 4. Verify results
// - departmentObservableDataRow1 (Added) is removed
// - departmentObservableDataRow2 (Deleted) is restored to Unchanged with original values
// - departmentObservableDataRow3 (Modified) is restored to Unchanged with original values
Table of Content POCO DataSet Observable Data Table 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.