DataGridView.ClearSelection Method (Int32, Int32, Boolean)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Cancels the selection of all currently selected cells except the one indicated, optionally ensuring that the indicated cell is selected.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

Protected Sub ClearSelection (
	columnIndexException As Integer,
	rowIndexException As Integer,
	selectExceptionElement As Boolean


Type: System.Int32

The column index to exclude.

Type: System.Int32

The row index to exclude.

Type: System.Boolean

true to select the excluded cell, row, or column; false to retain its original state.

Exception Condition

columnIndexException is greater than the highest column index.


columnIndexException is less than -1 when SelectionMode is FullRowSelect; otherwise, columnIndexException is less than 0.


rowIndexException is greater than the highest row index.


rowIndexException is less than -1 when SelectionMode is FullColumnSelect; otherwise, rowIndexException is less than 0.

A rowIndexException value of -1 represents a column header, and a columnIndexException value of -1 represents a row header.

This method is useful to clear the current selection without canceling the selection of the cell, row, or column indicated by the exception indexes.

If the SelectionMode property value allows individual cell selection, this method sets the Selected property of each cell to false, excluding the cell in the row and column specified. If the SelectionMode property value allows full row or column selection, this method also sets the Selected property of each row or column to false, excluding the row or column containing the specified cell.

The excluded cell, row, or column may or may not be in the selected state when this method is called. This method selects it if the selectExceptionElement parameter value is true. Depending on the selection mode, the entire row or column may also be selected as a result.

.NET Framework
Available since 2.0
Return to top