title: C# Load CSV into DataGrid
body: <p>So I have a CSV file:</p>
  
  <pre><code>    Header1,Header2,Header3,Header4
      Data11,Data12,Data13,Data14
      Data21,Data22,Data23,Data24
      Data31,Data32,Data33,Data34
      Data41,Data42,Data43,Data44
  </code></pre>
  
  <p>and a <code>DataGrid</code> in an WPF project. I cannot, for the life of me, get it to import. What I was trying to do before was add all the columns (<code>Header1</code>, <code>Header2</code>, <code>Header3</code>, <code>Header4</code>) then add the rows... but there didn't seem to be any way to add rows. So I tried using <code>ItemSource</code>... but no luck.</p>
  
  <p>So... how do I import a CSV file into a <code>System</code>.<code>Windows</code>.<code>Controls</code>.<code>DataGrid</code></p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>So I tried this:</p>
  
  <pre><code>    DataTable table = CSVReader.ReadCSVFile(fileName, true);
      dataGrid.ItemsSource = table.DefaultView;
  </code></pre>
  
  <p>And it seems to work... somewhat:
  <img src="https://i.stack.imgur.com/ox84I.png" alt="The Rows show up, but no columns or content"></p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>So after turning on <code>AutoGenerateColumns</code>, everything worked perfectly.</p>