Multiple Row Selection
- 7 minutes to read
In this mode, multiple data and/or group rows can be selected at one time. In a CardView, you can select multiple cards. In a TreeListView, you can select multiple nodes. To enable this mode, set the DataControlBase.SelectionMode property to MultiSelectMode.Row or MultiSelectMode.MultipleRow. The DataViewBase.NavigationStyle property must be set to GridViewNavigationStyle.Cell or GridViewNavigationStyle.Row.
Selecting Records in UI
End users can select multiple rows using Shift or Ctrl keys. Enable the TableView.UseIndicatorForSelection/TreeListView.UseIndicatorForSelection option to allow an end user to select a range of rows/nodes/cells by dragging the mouse along the Row Indicator Panel.
Web-style Row Selection
You can enable the Web Style Row Selection. When this feature is enabled, a Selector Column can be used to select/deselect individual rows and groups. To activate this feature, set the view’s TableView.ShowCheckBoxSelectorColumn property to true.
Note
- When the Web-style Row Selection feature is enabled, setting the TableView.RetainSelectionOnClickOutsideCheckBoxSelector property to true disables the Selection Rectangle feature.
- You cannot sort and filter by the Selector Column.
- Web-style row selection does not work with the InfiniteAsyncSource and InfiniteSource.
Selecting Records in Code
The GridControl provides multiple members which allow you to select/unselect multiple rows/cards/nodes:
Member | Description |
---|---|
Selects all rows/cards/nodes within a View. Unselects any selected rows/cards/nodes within a View. | |
Selects multiple rows/cards/nodes, while preserving the current selection (if any). | |
Selects the specified row (or the treelist node). Unselects the specified row (or the treelist node). | |
Gets or sets data objects that correspond to rows (or nodes in TreeListView) currently selected within a View. Get or sets the currently focused data row (if row multi-selection is disabled); or the first selected row (if row multi-selection is enabled). Gets or sets the currently focused data row. |
Selection Availability
You can dynamically control selection availability and prevent end-users from selecting or unselecting rows/nodes/cards.
Handle the DataViewBase.CanSelectRow or DataViewBase.CanUnselectRow event to dynamically allow or prevent any row/node/card selection.
Appearance Customization
Set the DataViewBase.EnableSelectedRowAppearance property to false, to disable the specific decoration of selected rows.
The image below demonstrates the visual difference between two controls with the disabled and enabled DataViewBase.EnableSelectedRowAppearance option. The first four rows are selected in both the grids.
Example: How To Select Rows That Contain The Specified Value
This example shows how to select rows whose 'UnitPrice' column contains a value equal to or greater than 20. To select rows, click the 'Select' button.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-select-rows-that-contain-the-specified-value-e1920.
using System;
using System.Collections.Generic;
public class Product {
public string CompanyName { get; set; }
public string Country { get; set; }
public string City { get; set; }
public double UnitPrice { get; set; }
public int Quantity { get; set; }
}
public class ProductList {
static public List<Product> GetData() {
List<Product> list = new List<Product>();
list.Add(new Product() { CompanyName = "Island Trading",
Country = "UK", City = "Cowes", UnitPrice = 19, Quantity = 10 });
list.Add(new Product() { CompanyName = "Reggiani Caseifici",
Country = "Italy", City = "Reggio Emilia", UnitPrice = 12.5, Quantity = 16 });
list.Add(new Product() { CompanyName = "Ricardo Adocicados",
Country = "Brazil", City = "Rio de Janeiro", UnitPrice = 19, Quantity = 12 });
list.Add(new Product() { CompanyName = "QUICK-Stop",
Country = "Germany", City = "QUICK-Stop", UnitPrice = 22, Quantity = 50 });
list.Add(new Product() { CompanyName = "Split Rail Beer & Ale",
Country = "USA", City = "Reggio Emilia", UnitPrice = 18, Quantity = 20 });
list.Add(new Product() { CompanyName = "Ernst Handel",
Country = "Austria", City = "Graz", UnitPrice = 21, Quantity = 52 });
list.Add(new Product() { CompanyName = "Save-a-lot Markets",
Country = "USA", City = "Boise", UnitPrice = 7.75, Quantity = 120 });
list.Add(new Product() { CompanyName = "Tortuga Restaurante",
Country = "Mexico", City = "México D.F.", UnitPrice = 21, Quantity = 15 });
list.Add(new Product() { CompanyName = "Bottom-Dollar Markets",
Country = "Canada", City = "Tsawwassen", UnitPrice = 44, Quantity = 16 });
return list;
}
}
Highlight Rows On Hover
Set the TableView.HighlightItemOnHover/TreeListView.HighlightItemOnHover property to true to enable highlighting rows when hovering:
<dxg:GridControl SelectionMode="Row">
<dxg:GridControl.View>
<dxg:TableView HighlightItemOnHover="True" />
</dxg:GridControl.View>
<!-- ... --->
</dxg:GridControl>