title: C# WPF DataGrid (ItemsSource = Database Table) - additional column: How to keep changes when (re-)sorting the DataGrid?
body: <p>got a tricky question here:
  I have a DataGrid that's being filled (DataGrid.ItemsSource) by an Access Table.</p>
  
  <p>What's best practice to show additional columns for the user and keep changes in this column upon (re-)sorting?</p>
  
  <p>In my case the additional column is a CheckBoxColumn for the user, to select those lines in the DataGrid he wants to edit. The checks disappear if you sort the DataGrid.</p>
  
  <p>Code:</p>
  
  <pre><code>using (OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "Test.accdb"))
  {
      string strDbCmd = "SELECT * FROM Table1";
      OleDbDataAdapter daOleDb = new OleDbDataAdapter(strDbCmd, connection);
      DataTable dtResult = new DataTable(); // this is actually a global
      daOleDb.FillSchema(dtResult, SchemaType.Source);
      daOleDb.Fill(dtResult);
      DataGrid1.ItemsSource = dtResult.DefaultView;
      DataGridCheckBoxColumn dgCol = new DataGridCheckBoxColumn();
      DataGrid1.Columns.Insert(0, dgCol);
  }
  </code></pre>
  
  <p>I cannot alter dtResult (which is actually a global) as I later on will use that to update the database:</p>
  
  <pre><code>// Later on somewhere else:
  OleDbDataAdapter daOleDb = new OleDbDataAdapter(strDbCmd, connection);
  // [...]
  daOleDb.Update(dtResult);
  </code></pre>
  
  <p>Now of course I could store all checks in a bool array or anything, but is there a clever solution to keep checks set upon sorting the DataGrid?</p>
  
  <p>Kinds regards!</p>