title: WPF How to convert from DataGrid to DataTable?
body: <p>Hi I am following along with this <a href="http://www.wpf-tutorial.com/datagrid-control/details-row/" rel="nofollow">guide</a> in order to learn about using DataGrid.</p>
  
  <p>The problem I am running into is how do I convert the data from the DataGrid into a DataTable?</p>
  
  <p>The code I am trying to get working is:</p>
  
  <pre><code>DataTable dt = ((DataView)dg.ItemsSource).ToTable();
  </code></pre>
  
  <p>but it gives me an error stating:</p>
  
  <blockquote>
    <p>Unable to cast object of type 
    'System.Collections.Generic.List`1[WPFProject.Person]' to type
    'System.Data.DataView'.</p>
  </blockquote>
  
  <p>My code is very much similar to the example except I use the class Person instead of user and I create a list of type Person in order to insert data into the datagrid.</p>
  
  <pre><code>public class Person
      {
          public bool CheckBox { get; set; }
          public int ID { get; set; }
          public string Name { get; set; }
      }
  </code></pre>
  
  <p>Thank you.</p>