DataControlBase.SelectionMode Property
Gets or sets whether multiple row/cell selection is enabled. This is a dependency property.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v24.2.Core.dll
NuGet Package: DevExpress.Wpf.Grid.Core
Declaration
Property Value
Type | Default | Description |
---|---|---|
MultiSelectMode | None | A MultiSelectMode enumeration value that specifies the selection mode. |
Available values:
Name | Description |
---|---|
None | Multi-selection is disabled. |
Row | Allows selection of multiple rows. |
Cell | Allows selection of multiple cells. |
MultipleRow | Allows toggling the selection of multiple rows. |
Remarks
- Disable Selection
- Set the DataViewBase.NavigationStyle property to
None
. - Enable Single Cell/Row Selection
- Set the
SelectionMode
property toNone
(default value) and the DataViewBase.NavigationStyle property toCell
/Row
. - Enable Multiple Cell Selection
- Set the
SelectionMode
property toCell
and the DataViewBase.NavigationStyle property toCell
(default value). - Enable Multiple Row Selection
- Set the
SelectionMode
property toRow
and the DataViewBase.NavigationStyle property toCell
/Row
. - Enable Touch-Friendly Multiple Row Selection
- Set the
SelectionMode
property toMultipleRow
and the DataViewBase.NavigationStyle property toCell
/Row
.
For the CardView, the SelectionMode
property affects card selection (similar to row selection in the TableView).
Example: How to Select Rows that Contain the Specified Value
This example shows how to select rows whose Unit Price column contains a value greater than or equal to the specified value. To select rows, click the Select button.
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<dxg:GridControl ItemsSource="{Binding Products}" AutoGenerateColumns="AddNew" SelectionMode="Row" SelectedItems="{Binding Selection}">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" FadeSelectionOnLostFocus="False"/>
</dxg:GridControl.View>
</dxg:GridControl>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock Text="Minimum Price:" TextAlignment="Right" Padding="4"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="0,0,5,0" Width="50"/>
<Button Content="Select" HorizontalAlignment="Left" Command="{Binding SelectRowsCommand}" CommandParameter="{Binding Text, ElementName=textBox}"/>
</StackPanel>
</Grid>
public class ViewModel : ViewModelBase {
public ViewModel() {
Products = ProductList.GetData();
Selection = new ObservableCollection<Product>() { Products.ElementAt(0) };
}
public ObservableCollection<Product> Products { get { return this.GetValue<ObservableCollection<Product>>(); } set { SetValue(value); } }
public ObservableCollection<Product> Selection { get { return this.GetValue<ObservableCollection<Product>>(); } set { SetValue(value); } }
[Command]
public void SelectRows(string textValue) {
var value = double.Parse(textValue);
Selection = new ObservableCollection<Product>(from item in Products where item.UnitPrice >= value select item);
}
public bool CanSelectRows(string textValue) {
return double.TryParse(textValue, out double value);
}
}
Example: How to Change the Appearance of Focused and Selected Cells
This example demonstrates how to use the View’s CellStyle property to define a custom appearance for focused and selected cells.
<Window.Resources>
<Style x:Key="SelectionStateCellStyle" TargetType="dxg:LightweightCellEditor">
<Style.Triggers>
<Trigger Property="SelectionState" Value="Selected">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="SelectionState" Value="FocusedAndSelected">
<Setter Property="Background" Value="Gray"/>
<Setter Property="Foreground" Value="Black"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Grid>
<dxg:GridControl x:Name="grid" AutoGenerateColumns="AddNew" SelectionMode="Cell">
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True" CellStyle="{StaticResource SelectionStateCellStyle}"/>
</dxg:GridControl.View>
</dxg:GridControl>
</Grid>
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the SelectionMode property.
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.