ClearSelection Method
The ClearSelection method clears the selection state for all rows in a table by setting
IDataRow.Selected to false for every row.
This helper is intended for UI-oriented scenarios where a table is used as a selectable list (for example, when your application allows multi-row selection and you want to clear all selections in one operation).
/// <summary>
/// Clears selection
/// </summary>
/// <param name="dataTable">Data table</param>
public static void ClearSelection(this IDataTable? dataTable)
Namespace: PocoDataSet.Extensions
Assembly: PocoDataSet.Extensions.dll
dataTable is null, returns immediately.dataTable.Rows and sets Selected = false.
// 1. Create an empty data set and a table
IDataSet dataSet = DataSetFactory.CreateDataSet();
IDataTable employeeTable = dataSet.AddNewTable("Employee");
employeeTable.AddColumn("Id", DataTypeNames.INT32);
employeeTable.AddColumn("FirstName", DataTypeNames.STRING);
employeeTable.AddColumn("LastName", DataTypeNames.STRING);
// 2. Add several rows and set their Selected flag to true
IDataRow employeeDataRow1 = employeeTable.AddNewRow();
employeeDataRow1["Id"] = 1;
employeeDataRow1["FirstName"] = "John";
employeeDataRow1["LastName"] = "Doe";
employeeDataRow1.Selected = true;
IDataRow employeeDataRow2 = employeeTable.AddNewRow();
employeeDataRow2["Id"] = 2;
employeeDataRow2["FirstName"] = "Sara";
employeeDataRow2["LastName"] = "Gor";
employeeDataRow2.Selected = true;
// Call ClearSelection to clear all selections
employeeTable.ClearSelection();
Selected flag. It does not change row values and does not affect
DataRowState.
Selected is a UI-oriented property. If your table does not use selection, calling this method has no practical effect.
Table of Content POCO DataSet DataTable Extensions Group DataTable 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.