DeleteRow Extension Method
Deletes an observable row from an observable table using the standard POCO DataSet row-state semantics. This method is designed for UI usage where the user can create, edit, and delete rows before saving.
Added, the method removes it from the table (undoes creation).Unchanged or Modified, the method calls Delete() (soft delete).Deleted or Detached, nothing happens.
The method first checks that both table and row are non-null and that the row belongs to the table (via ContainsRow).
/// <summary>
/// Deletes row from table
/// </summary>
/// <param name="observableDataTable">Observable data table</param>
/// <param name="observableDataRow">Observable data row</param>
public static void DeleteRow(this IObservableDataTable? observableDataTable, IObservableDataRow? observableDataRow)
Namespace: PocoDataSet.ObservableExtensions
Assembly: PocoDataSet.ObservableExtensions.dll
// 1. Create an empty data set and a table
IObservableDataSet observableDataSet = new ObservableDataSet();;
IObservableDataTable employeeObservableDataTable = observableDataSet.AddNewTable("Employee");
employeeObservableDataTable.AddColumn("Id", DataTypeNames.INT32);
employeeObservableDataTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeObservableDataTable.AddColumn("LastName", DataTypeNames.STRING);
// 2. Add a row in Added state
IObservableDataRow employeeObservableDataRow1 = employeeObservableDataTable.AddNewRow();
employeeObservableDataRow1["Id"] = 1;
employeeObservableDataRow1["FirstName"] = "John";
employeeObservableDataRow1["LastName"] = "Doe";
// 3. Add a row in Unchanged state
IObservableDataRow employeeObservableDataRow2 = employeeObservableDataTable.AddNewRow();
employeeObservableDataRow2["Id"] = 2;
employeeObservableDataRow2["FirstName"] = "Sara";
employeeObservableDataRow2["LastName"] = "Gor";
employeeObservableDataRow2.AcceptChanges();
// 3. Add a row in Modified state
IObservableDataRow employeeObservableDataRow3 = employeeObservableDataTable.AddNewRow();
employeeObservableDataRow3["Id"] = 1;
employeeObservableDataRow3["FirstName"] = "Paul";
employeeObservableDataRow3["LastName"] = "Carry";
employeeObservableDataRow3.AcceptChanges();
employeeObservableDataRow3["FirstName"] = "Tom";
// Call DeleteRow method on each row
// Added row removed from table
employeeObservableDataTable.DeleteRow(employeeObservableDataRow1);
// Unchanged row marked as deleted
employeeObservableDataTable.DeleteRow(employeeObservableDataRow2);
// Modified row marked as deleted
employeeObservableDataTable.DeleteRow(employeeObservableDataRow3);
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.