wpf-devexpress-dot-xpf-dot-grid-dot-datacontrolbase-a7f55d48.md
Gets or sets whether multiple row/cell selection is enabled. This is a dependency property.
Namespace : DevExpress.Xpf.Grid
Assembly : DevExpress.Xpf.Grid.v25.2.Core.dll
NuGet Package : DevExpress.Wpf.Grid.Core
public MultiSelectMode SelectionMode { get; set; }
Public Property SelectionMode As MultiSelectMode
| 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.
|
Tip
Topics :
Disable SelectionSet the DataViewBase.NavigationStyle property to None.Enable Single Cell/Row SelectionSet the SelectionMode property to None (default value) and the DataViewBase.NavigationStyle property to Cell/Row.Enable Multiple Cell SelectionSet the SelectionMode property to Cell and the DataViewBase.NavigationStyle property to Cell (default value).Enable Multiple Row SelectionSet the SelectionMode property to Row and the DataViewBase.NavigationStyle property to Cell/Row.Enable Touch-Friendly Multiple Row SelectionSet the SelectionMode property to MultipleRow and the DataViewBase.NavigationStyle property to Cell/Row.
For the CardView, the SelectionMode property affects card selection (similar to row selection in the TableView).
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.
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);
}
}
Public Class ViewModel
Inherits ViewModelBase
Public Sub New()
Products = ProductList.GetData()
Selection = New ObservableCollection(Of Product)() From {Products.ElementAt(0)}
End Sub
Public Property Products As ObservableCollection(Of Product)
Get
Return GetValue(Of ObservableCollection(Of Product))()
End Get
Set(ByVal value As ObservableCollection(Of Product))
SetValue(value)
End Set
End Property
Public Property Selection As ObservableCollection(Of Product)
Get
Return GetValue(Of ObservableCollection(Of Product))()
End Get
Set(ByVal value As ObservableCollection(Of Product))
SetValue(value)
End Set
End Property
<Command>
Public Sub SelectRows(ByVal textValue As String)
Dim value = Double.Parse(textValue)
Selection = New ObservableCollection(Of Product)(From item In Products Where item.UnitPrice >= value Select item)
End Sub
Public Function CanSelectRows(ByVal textValue As String) As Boolean
Dim value As Double = Nothing
Return Double.TryParse(textValue, value)
End Function
End Class
This example demonstrates how to use the View’s CellStyle property to define a custom appearance for 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.
<dxg:GridControl Name="grid"
SelectionMode="Row"
AutoGenerateColumns="AddNew"
use-unbounddatasource-to-populate-wpf-data-grid-with-data/CS/UnboundSource/MainWindow.xaml#L29
<dxg:GridControl ItemsSource="{Binding Data, ElementName=unboundDataSource1}" SelectionMode="Row">
<dxg:GridColumn FieldName="UnboundFirstName" />
<dxg:GridControl AutoGenerateColumns="AddNew" ItemsSource="{Binding}" SelectionMode="Cell">
<dxg:GridControl.View>
wpf-grid-select-child-rows-in-groups-on-click/CS/GridGroupSelect/MainWindow.xaml#L8
<Grid>
<dxg:GridControl Name="grid" ItemsSource="{Binding}" SelectionMode="Row">
<dxg:GridControl.Columns>
wpf-data-grid-select-rows-that-contain-specific-value/CS/DXGrid_SelectRows/Window1.xaml#L15
</Grid.RowDefinitions>
<dxg:GridControl ItemsSource="{Binding Products}" AutoGenerateColumns="AddNew" SelectionMode="Row" SelectedItems="{Binding Selection}">
<dxg:GridControl.View>
See Also