wpfcheckboxdatagrid

WPF Checkbox check moves on scrolling


I have a datagrid with the first column being a DataGridTemplateColumn of type Checkbox.

<DataGridTemplateColumn Header="Select">
     <DataGridTemplateColumn.CellTemplate>
           <DataTemplate >
                 <CheckBox  Name="chkSelectForMassRequest" Tag="{Binding AcctNum}" IsChecked="{Binding Path=IsSelected, UpdateSourceTrigger=PropertyChanged}" ClickMode="Press" Unchecked="chkSelectForMassRequest_Checked" Checked="chkSelectForMassRequest_Checked" ></CheckBox>
            </DataTemplate>
     </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

The strange thing is that when the user checks a few checkboxes and then scrolls down through the data grid, some of the check marks disappear from the original checkboxes and reappear in the newly visible rows even though the user did not check them. My question is, how do I preserve the check marks in all rows regardless if the row is visible or not. And, how do I prevent check marks from moving around on scrolling?

Thanks in advance, Mark


Solution

  • This is because the DataGrid has virtualization switched on by default which is conflicting with your UpdateSourceTrigger directive within your Binding.

    Either remove the UpdateSourceTrigger and make the binding TwoWay, or add 'VirtualizingStackPanel.VirtualizationMode="Standard"' in the XAML that declares the DataGrid