A newer version of this page is available. Switch to the current version.

DataViewBase.SelectedRowsSource Property

Obsolete. Gets or sets the source of selected rows. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v19.1.Core.dll

Declaration

[Obsolete("Use the DataControlBase.SelectedItems property instead")]
public IList SelectedRowsSource { get; set; }
<Obsolete("Use the DataControlBase.SelectedItems property instead")>
Public Property SelectedRowsSource As IList

Property Value

Type Description
IList

The collection of selected rows.

Remarks

Use the SelectedRowsSource property to synchronize rows selected within the grid with a ViewModel (MVVM). The source collection should implement INotifyCollectionChanged. Otherwise, changes made within the ViewModel are not reflected by the grid control.

Examples

This example demonstrates how to bind GridControl's selected rows to a property in ViewModel in a MVVM-based application. The SelectionAttachedBehavior helper class used in this sample, provides a bindable SelectedItemsSource property, that can be used to define selection at the ViewModel level. Note, we made the SelectionAttachedBehavior class as generic as possible, and the same approach can also be used for other controls that support multiple selection. This example demonstrates how this can be done when working with the standard ListBox control, as well as with the standard DataGrid.

<Window x:Class="WPFGridMVVMSelection.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <dxg:GridControl ItemsSource="{Binding Source}" AutoGenerateColumns="AddNew" SelectionMode="Row" SelectedItems="{Binding Selection}" >
            <dxg:GridControl.View>
                <dxg:TableView NavigationStyle="Row" />
            </dxg:GridControl.View>
        </dxg:GridControl>
        <ListView SelectionMode="Multiple" Grid.Column="1" ItemsSource="{Binding Source}"
                  dx:SelectionAttachedBehavior.SelectedItemsSource="{Binding Selection}" />
        <dxg:GridControl Grid.Column="2" ItemsSource="{Binding Source}" AutoGenerateColumns="AddNew" SelectionMode="Row" SelectedItems="{Binding Selection}"> 
            <dxg:GridControl.View>
                <dxg:TableView NavigationStyle="Row" />
            </dxg:GridControl.View>
        </dxg:GridControl>
        <dxg:GridControl Grid.Column="3" ItemsSource="{Binding Source}" AutoGenerateColumns="AddNew" SelectionMode="Row" SelectedItems="{Binding Selection}">
            <dxg:GridControl.View>
                <dxg:CardView NavigationStyle="Row" />
            </dxg:GridControl.View>
        </dxg:GridControl>
        <Button Grid.Row="1" Grid.ColumnSpan="2" Content="Select Odd Rows" Command="{Binding SelectOddRowsCommand}"/>
        <Button Grid.Row="1" Grid.Column="2" Grid.ColumnSpan="2" Content="Delete Selected Rows" Command="{Binding DeleteSelectedRowsCommand}" />
    </Grid>
</Window>
See Also