Επεξεργασία

Κοινή χρήση μέσω


DataGridView.ClearSelection Method

Definition

Cancels the selection of currently selected cells.

Overloads

ClearSelection(Int32, Int32, Boolean)

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

ClearSelection()

Clears the current selection by unselecting all selected cells.

ClearSelection(Int32, Int32, Boolean)

Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs

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

protected:
 void ClearSelection(int columnIndexException, int rowIndexException, bool selectExceptionElement);
protected void ClearSelection (int columnIndexException, int rowIndexException, bool selectExceptionElement);
member this.ClearSelection : int * int * bool -> unit
Protected Sub ClearSelection (columnIndexException As Integer, rowIndexException As Integer, selectExceptionElement As Boolean)

Parameters

columnIndexException
Int32

The column index to exclude.

rowIndexException
Int32

The row index to exclude.

selectExceptionElement
Boolean

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

Exceptions

columnIndexException is greater than the highest column index.

-or-

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

-or-

rowIndexException is greater than the highest row index.

-or-

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

Remarks

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.

See also

Applies to

ClearSelection()

Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs
Source:
DataGridView.Methods.cs

Clears the current selection by unselecting all selected cells.

public:
 void ClearSelection();
public void ClearSelection ();
member this.ClearSelection : unit -> unit
Public Sub ClearSelection ()

Examples

The following code example clears the selection of the DataGridView. To run this example, paste the code into a form that contains a DataGridView named dataGridView1 and a Button named clearSelectionButton, and ensure all events are associated with their event handlers.

private void clearSelectionButton_Click(object sender, EventArgs e)
{
    dataGridView1.ClearSelection();
}
Private Sub clearSelectionButton_Click(ByVal sender As Object, _
    ByVal e As EventArgs) Handles clearSelectionButton.Click

    dataGridView1.ClearSelection()

End Sub

Remarks

When this method is called, each column and row's Selected property is set to false.

See also

Applies to