Skip to main content
A newer version of this page is available. .

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.v22.1.Core.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public MultiSelectMode SelectionMode { get; set; }

Property Value

Type Description
MultiSelectMode

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

Multiple row/cell selection is not allowed if the DataViewBase.NavigationStyle property is set to GridViewNavigationStyle.None and/or the SelectionMode property is set to MultiSelectMode.None.

To enable multiple row selection, set the SelectionMode property to MultiSelectMode.Row.

To enable touch-friendly multiple row selection, set the SelectionMode property to MultiSelectMode.MultipleRow.

To enable multiple cell selection (block selection), set the SelectionMode property to MultiSelectMode.Cell.

To enable single row selection, set the DataViewBase.NavigationStyle property to GridViewNavigationStyle.Row and/or the SelectionMode property to MultiSelectMode.None.

For the CardView, setting the SelectionMode property affects card selection (similar to row selection in the TableView).

To disable card selection, set the SelectionMode property to MultiSelectMode.None or MultiSelectMode.Cell.

Example: How to Select Rows that Contain the Specified Value

This example shows how to select rows whose Unit Price column contains a value equal to or greater than the specified value. To select rows, click the Select button.

Grid - Select Rows with the Specified Value

View Example: Select Rows that Contain the Specified Value

<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.

Customize Focused and Selected Cells

View Example: Change the Appearance of 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>

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.

See Also