Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Expand]Grouping
   [Expand]Sorting
   [Expand]Summaries
   [Expand]Data Editing
   [Expand]Filtering and Locating Rows
   [Collapse]Focus and Selection Handling
     Focusing Cells
     Moving Row Focus
     Using Navigators
     Multiple Row and Cell Selection
     Multiple Row Selection via Built-In Check Column
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Hints
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Multiple Row and Cell Selection

The Grid Control supports single and multiple row/card selection in the GridView, BandedGridView, AdvBandedGridView, LayoutView, CardView and WinExplorerView. The GridView and BandedGridView additionally provide the multiple cell selection mode. This topic covers information on these modes and related API.

Expanded Online Video

Expanded Single Row/Card Selection Mode

This is the default selection mode for all Views in which a row/card can only be focused (selected) one at a time.

The table below lists members that can be used to focus (select) records, access the currently focused record and respond to the focus movement.

Member Description
ColumnView.FocusedRowHandle Specifies the focused row handle.

This property allows you to get the focused (selected) row/card. Assigning a value to this property focuses (selects) the specified row/card at a time.

ColumnView.FocusedRowChanged Allows you to respond to a focus moving to another row.
ColumnView.SelectedRowsCount In single row/card selection mode, returns 1.
ColumnView.GetSelectedRows In single row/card selection mode, returns an array that contains a single element that identifies the focused row handle (ColumnView.FocusedRowHandle).

Expanded Multiple Row/Card Selection Mode

In this mode, multiple rows/cards can be selected at one time. By selecting rows, you visually mark them. You can then perform various operations on selected rows (copy to the Clipboard (as text), delete, drag, etc.).

By default, selected rows are painted using the same appearance settings as for the focused row, although it is possible to use different appearance settings to paint selected and focused rows. For the difference between focus and selection, see the Focused Row vs Selected Row subsection below.

To enable multiple row/card selection in all Views, set the ColumnViewOptionsSelection.MultiSelect property (accessible from the View's ColumnView.OptionsSelection object) to true.

The GridView provides the additional GridOptionsSelection.MultiSelectMode property, with which you can select between two multiple row selection modes: GridMultiSelectMode.RowSelect (default) and GridMultiSelectMode.CheckBoxRowSelect.

In GridMultiSelectMode.RowSelect mode, an end-user can select rows with the keyboard and mouse.

In GridMultiSelectMode.CheckBoxRowSelect mode, the GridView displays an additional 'Check' column containing check boxes in each row. An end-user can toggle check boxes to change row selection. Row selection with the keyboard and mouse are also supported.

See the Multiple Row Selection via Built-In Check Column topic to learn more.

Expanded Focused Row vs Selected Row

The focused row/card is the row that accepts input from an end-user. There can only be one focused row in a View, regardless of selection mode. Compared to row focusing, row selection is only a visual feature designated for highlighting certain rows.

In multiple row/card selection mode, when an end-user focuses a new row with either the Arrow keyboard keys or using the mouse, then that row is selected (highlighted). When you focus a certain row in code (e.g., with the ColumnView.FocusedRowHandle property), this row is not automatically selected (highlighted). You can select/deselect the focused row in code when required. An end-user can also toggle the selected state for the focused row using the mouse and keyboard, as shown in the End-User Capabilities - Select Grid Rows and Cards topic.

The following images demonstrate the selected and deselected states for a focused row.

Focused Row is selected

The ColumnView.GetSelectedRows method will return three row handles, including the focused row handle.

Focused Row is deselected

The ColumnView.GetSelectedRows method will return two handles that correspond to selected rows. The focused row handle will not be included in the method's resulting array.

The table below lists members used in working with selection.

Member Description
ColumnView.SelectRow Adds a row/card to the current selection.
GridView.SelectRows
ColumnView.SelectRange
Adds a range of rows/cards to the selection.
ColumnView.UnselectRow Removes a row/card from the current selection.
ColumnView.ClearSelection Unselects any selected rows/cards.
ColumnView.FocusedRowHandle Specifies the focused row handle.

In this mode, the property does not allow you to select rows/cards.

ColumnView.SelectedRowsCount Returns the number of currently selected rows.
ColumnView.GetSelectedRows Returns an array of the handles of the selected rows.
ColumnView.SelectionChanged Allows you to perform actions when the selection is changed.
BaseView.BeginSelection
BaseView.EndSelection
This method pair prevents excessive updates when performing multiple successive selection modifications using code. See below.

Each time the selection is changed in multiple selection mode, the ColumnView.SelectionChanged event is generated. You can handle it to perform specific actions. To respond to row focus moving from one row to another (even when multiple selection mode is not used), you can handle the ColumnView.FocusedRowChanged event.

When you make multiple successive calls to the methods that change selection, it is best to wrap such calls in calls to the BaseView.BeginSelection/BaseView.EndSelection methods. This prevents the ColumnView.SelectionChanged event from being fired repeatedly, and thus improves your application's performance. See the Batch Modifications Overview topic for more information.

Expanded Multiple Cell Selection Mode

This selection mode, supported by GridView and BandedGridView, allows an end-user to select contiguous blocks of cells as well as individual cells within different rows. Multiple rows can also be selected in their entirety, for instance, by clicking the Row Indicator Panel.

To enable multiple cell selection mode, set the ColumnViewOptionsSelection.MultiSelect property to true and the GridOptionsSelection.MultiSelectMode property to GridMultiSelectMode.CellSelect.

Similar to the previous selection mode, in this mode, the focused row can be in the selected and deselected state.

The following table lists the methods to select/unselect cells.

Member Description
GridView.SelectCell Selects a specific cell.
GridView.SelectCells Selects a range of cells.
ColumnView.SelectAll Selects all rows/cards within the View.
GridView.UnselectCell Removes the specified cell from the current selection.
GridView.UnSelectCells Removes the specified block of cells from the selection.
GridView.GetSelectedCells Returns selected cells.
ColumnView.GetSelectedRows Returns the handles of the rows that contain the selected cells.

Also, see the list of methods for working with the selection provided in the previous section. When applied in multiple cell selection mode, these methods will affect all cells that belong to the specified row(s).

Expanded Common Methods to Work with Selection and Rows

Member Description
BaseView.CopyToClipboard Copies the focused or selected record(s) to the Clipboard as text.
ColumnView.DeleteRow Deletes a specific row/card.
ColumnView.DeleteSelectedRows Deletes the focused or selected rows.
ColumnView.GetRow Returns an object that represents a specified row.
ColumnView.GetDataRow Returns a System.Data.DataRow object that represents a specified row.
ColumnView.GetRowCellValue
ColumnView.GetFocusedRowCellValue
Gets the value in a row's field.
ColumnView.GetRowCellDisplayText
ColumnView.GetFocusedRowCellDisplayText
Gets the text representation of a row's value.
ColumnView.SetRowCellValue
ColumnView.SetFocusedRowCellValue
Assigns a value to a row's cell.

Expanded End-User Capabilities

An end-user can select rows/cards and cells with a mouse and keyboard. Please refer to the End-user Capabilities.Selecting Rows topic for more details.

Expanded Appearance Settings

By default, selected and focused rows are painted using the same appearance settings. To customize them, use the following properties that are available using a View's Appearance object (GridView.Appearance, CardView.Appearance, etc.).

Member Description
GridViewAppearances.FocusedRow Contains appearance settings used to paint the currently focused row.
GridViewAppearances.SelectedRow Contains the appearance settings used to paint the selected rows.
GridViewAppearances.HideSelectionRow Contains the appearance settings used to paint the selected rows when the grid control is not focused.
CardViewAppearances.FocusedCardCaption Contains the appearance settings used to paint the caption of the focused card.
CardViewAppearances.SelectedCardCaption Contains the appearance settings used to paint the captions of selected cards.
CardViewAppearances.HideSelectionCardCaption Contains the appearance settings used to paint the captions of selected cards when the grid control is not focused.

In specific instances, you may need to prevent the focused row from being highlighted in the GridView or its descendant. To do this, set the GridOptionsSelection.EnableAppearanceFocusedRow property to false. The coloring of a focused cell can be disabled using the GridOptionsSelection.EnableAppearanceFocusedCell option.

To prevent selected rows from being highlighted in a specific manner when the grid control is not focused, use the GridOptionsSelection.EnableAppearanceHideSelection property.

Expanded Example - Obtain the Selected Rows

This example demonstrates how to obtain selected rows and then change their field values. The handles of selected rows are retrieved by the ColumnView.GetSelectedRows method. Since row handles reflect the order in which rows are displayed within a View, modifying a single row may affect the handles of other rows (e.g., if data is sorted and/or filtered). To prevent possible data corruption, a target row is modified using an underlying record object (in this example, a DataRow object). DataRows that correspond to selected rows are retrieved using the ColumnView.GetDataRow method and are stored in an array prior to data modification.

Bear in mind that when updating multiple rows, Grid View is updated after every row modification. So, to prevent unnecessary updates, you should enclose your code within calls to the BaseView.BeginUpdate and BaseView.EndUpdate methods. Refer to the Batch Modifications Overview document for details.

Expanded Example - Highlight the Entire Focused Row

This example shows how to paint the focused cell using the same appearance as the entire focused row:

To prevent the focused cell from being highlighted, set the GridOptionsSelection.EnableAppearanceFocusedCell property to false. To prevent the dotted focus rectangle from being painted around the focused cell, use the GridView.FocusRectStyle property.

Expanded See Also

How would you rate this topic?​​​​​​​