title: Automatic checking and unchecking of checkboxes in WPF DataGrid on mouse scroll
body: <p>I am developing a WPF application in which I need to send SMS to only those contacts that are checked in a DataGrid.</p>
  
  <p>After checking the desired contacts in the DataGrid, I am facing problems when I scroll down/up. The checked property of the checkboxes in the DataGrid gets changed randomly.</p>
  
  <p>I came across some solutions that suggested to add the following properties:</p>
  
  <ul>
  <li>VirtualizingStackPanel.VirtualizationMode="Standard" in DataGrid</li>
  <li>VirtualizingStackPanel.IsVirtualizing="True" in DataGrid (When I set it to False, the application becomes totally unresponsive)</li>
  <li>UpdateSourceTrigger="PropertyChanged" in CheckBox Binding</li>
  <li>EnableRowVirtualization="True" in DataGrid</li>
  <li>EnableColumnVirtualization="True" in DataGrid</li>
  </ul>
  
  <p>I tried them all, but none of them worked.</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;StackPanel Orientation="Horizontal"&gt;
          &lt;DataGrid x:Name="smsgrid" VirtualizingStackPanel.VirtualizationMode="Standard" VirtualizingStackPanel.IsVirtualizing="True" Margin="10,20,0,10" AutoGenerateColumns="False" IsReadOnly="True" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False"&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTemplateColumn&gt;
                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;CheckBox x:Name="chkbox" Checked="chkbox_Checked" Unchecked="chkbox_Checked"&gt;&lt;/CheckBox&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/DataGridTemplateColumn&gt;
                  &lt;DataGridTextColumn Header="ID" Binding="{Binding ID}"&gt;&lt;/DataGridTextColumn&gt;
                  &lt;DataGridTextColumn Header="Name" Binding="{Binding Name}"&gt;&lt;/DataGridTextColumn&gt;
                  &lt;DataGridTextColumn Header="Mobile no." Binding="{Binding Mobile1}"&gt;&lt;/DataGridTextColumn&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
          ...
  &lt;StackPanel&gt;
  </code></pre>
  
  <p>I am using the StackPanel to stack a LogIn page horizontally (not pasted in the above XAML) and a List to store the mobile number if the corresponding checkbox is selected. I also noted that the values in the List remains unchanged as the values of the checked property of checkboxes changes.</p>
  
  <p>It would be really nice if I get a solution for avoiding the automatic checking and unchecking of checkboxes in the DataGrid.</p>
  
  <p>Thank You!</p>