ClearRows Method
The ClearRows method removes all rows from an observable data table.
Internally, it calls RemoveRowAt method
for each row, ensuring that the observable layer can raise change notifications and keep its
state consistent with the inner table.
This method is typically used when you intentionally discard local edits and replace a table's current result set (for example, a new search or a full reload).
/// <summary>
/// Deletes observable row from observable table (delegates to inner table)
/// </summary>
/// <param name="observableDataTable">Observable data table</param>
public static void ClearRows(this IObservableDataTable? observableDataTable)
Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll
observableDataTable is null, the method returns immediately (no-op).
observableDataTable.InnerDataTable.Rows.Count - 1 down to 0.
observableDataTable.RemoveRowAt(i).
Removing from the end avoids index shifting issues while the collection shrinks.
The following example clears an observable table before loading a new result set:
// 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 departmentObservableDataRow = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow["Id"] = 1;
departmentObservableDataRow["Name"] = "Reception";
// Row in Deleted state
departmentObservableDataRow = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow["Id"] = 2;
departmentObservableDataRow["Name"] = "Emergency";
departmentObservableDataRow.AcceptChanges();
departmentObservableDataRow.Delete();
// Row in Modified state
departmentObservableDataRow = departmentObservableDataTable.AddNewRow();
departmentObservableDataRow["Id"] = 3;
departmentObservableDataRow["Name"] = "Emergency";
departmentObservableDataRow.AcceptChanges();
departmentObservableDataRow["Name"] = "Finance";
// 3. Discard current rows (for example, user starts a new search)
departmentObservableDataTable.ClearRows();
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.