1
votes

below is my datagrid's definition:

<DataGrid
    Name="ODataGrid"
    AutoGenerateColumns="False"
    Grid.Row="0"
    Grid.Column="0"
    CanUserAddRows="False"
    AlternationCount="2"
    HeadersVisibility="All"
    IsReadOnly="True"                               
    SelectionUnit="FullRow"
    HorizontalAlignment="Stretch"
    VerticalAlignment="Stretch"
    Background="#EBF0F0"
    AlternatingRowBackground="#E9E8EF"
    HorizontalGridLinesBrush="#7F7F7F"
    VerticalGridLinesBrush="#7F7F7F"
    SelectedItem="{Binding vmItem}"
    CellStyle="{StaticResource ODataGridCellStyle}"
    ItemsSource="{Binding vmResults}"
    Tag="{Binding DataContext, ElementName=BaseGrid}">

Below are the steps I took to get the error.

  1. The first row was selected by default.
  2. I select another row in the datagrid.
  3. I do a sort by clicking on one of the column header.
  4. I do a scroll by dragging the vertical scroll bar.
  5. The initial first row was somehow auto selected.
  6. So now, there are 2 rows being selected.

Why this behaviour? Anyway to prevent the auto select on scroll? Thanks.

2
Have you checked that DataGrid dont have set SelectionMode property Set dg.SelectionMode = DataGridSelectionMode.Extended will select more than one row selectd ? - Ashok Rathod
Hi, my SelectionMode has to be Extended, hence I cannot set it to Single, although that will resolve the issue. - Low

2 Answers

1
votes
EnableRowVirtualization="False"

In the datagrid properties.

-2
votes

add this property in datagrid

VirtualizingStackPanel.IsVirtualizing="False"