windowsforms-devexpress-dot-xtragrid-dot-views-dot-base-dot-columnview-f7168d4f.md
Unselects any selected rows in the current View when multiple row selection is in effect.
Namespace : DevExpress.XtraGrid.Views.Base
Assembly : DevExpress.XtraGrid.v25.2.dll
NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation
public virtual void ClearSelection()
Public Overridable Sub ClearSelection
The ClearSelection method unselects all the selected rows (cards) when multiple row selection is in effect (the ColumnViewOptionsSelection.MultiSelect property is set to true ). If multiple row selection is not in effect, this method does nothing. To unselect an individual row (card), call the View’s ColumnView.UnselectRow method.
After you call the ClearSelection method, the ColumnView.GetSelectedRows method returns null ( Nothing in Visual Basic).
Refer to the Multiple Row and Cell Selection topic for general information about row (card) selections.
Note
Detail pattern Views do not contain data and they are never displayed within XtraGrid. So, the ClearSelection member must not be invoked for these Views. The ClearSelection member can only be used with Views that display real data within the Grid Control. Use the following methods to access these Views with which an end user interacts at runtime.
The code sample below illustrates how to select all grid cells when users press CTRL+A, and how to clear the selection when users press CTRL+N.
gridView1.OptionsSelection.MultiSelect = true;
gridView1.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect;
gridView1.KeyDown += GridView1_KeyDown;
private void GridView1_KeyDown(object sender, KeyEventArgs e)
{
GridView view = sender as GridView;
if (e.Control)
switch (e.KeyCode)
{
case Keys.A:
view.SelectAll();
e.Handled = true;
break;
case Keys.N:
view.ClearSelection();
e.Handled = true;
break;
}
}
gridView1.OptionsSelection.MultiSelect = True
gridView1.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect
AddHandler gridView1.KeyDown, AddressOf GridView1_KeyDown
private void GridView1_KeyDown(Object sender, KeyEventArgs e)
Dim view As GridView = TryCast(sender, GridView)
If e.Control Then
Select Case e.KeyCode
Case Keys.A
view.SelectAll()
e.Handled = True
Case Keys.N
view.ClearSelection()
e.Handled = True
End Select
End If
The following code snippets (auto-collected from DevExpress Examples) contain references to the ClearSelection() method.
Note
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.
winforms-grid-move-cell-using-drag-drop/CS/Classes/GridViewHelper.cs#L113
(view as GridView).SetRowCellValue(lastMouseDownMoveCell.RowHandle, lastMouseDownMoveCell.Column, val);
(view as GridView).ClearSelection();
(view as GridView).SelectCell(lastMouseDownMoveCell.RowHandle, lastMouseDownMoveCell.Column);
winforms-preserve-grid-state-on-refresh/CS/RefreshHelperClass.cs#L138
try {
view.ClearSelection();
for(int i = 0; i < list.Count; i++)
winforms-gridlookupedit-multiple-item-selection/CS/Form1.cs#L85
view.BeginSelection();
view.ClearSelection();
if(edit != null)
winforms-grid-select-detail-rows-when-selecting-master-row/CS/MasterDetailSelectionHelper.cs#L68
{
detailView.ClearSelection();
}
winforms-grid-select-rows-with-mouse/CS/WindowsApplication1/Form1.cs#L32
view.BeginSelection();
view.ClearSelection();
view.SelectRange(startRow, endRow);
winforms-grid-move-cell-using-drag-drop/VB/Classes/GridViewHelper.vb#L109
TryCast(view, GridView).SetRowCellValue(lastMouseDownMoveCell.RowHandle, lastMouseDownMoveCell.Column, val)
TryCast(view, GridView).ClearSelection()
TryCast(view, GridView).SelectCell(lastMouseDownMoveCell.RowHandle, lastMouseDownMoveCell.Column)
winforms-preserve-grid-state-on-refresh/VB/RefreshHelperClass.vb#L147
Try
view.ClearSelection()
For i As Integer = 0 To list.Count - 1
winforms-gridlookupedit-multiple-item-selection/VB/Form1.vb#L80
view.BeginSelection()
view.ClearSelection()
If edit IsNot Nothing Then
winforms-grid-select-detail-rows-when-selecting-master-row/VB/MasterDetailSelectionHelper.vb#L53
Else
detailView.ClearSelection()
End If
winforms-grid-select-rows-with-mouse/VB/WindowsApplication1/Form1.vb#L26
view.BeginSelection()
view.ClearSelection()
view.SelectRange(startRow, endRow)
See Also