title: How do I automatically bind a string array to a WPF DataGrid?
body: <p>I have a <code>DataGrid</code> inside of a <code>UserControl</code>. It looks like this:</p>
  
  <pre><code>&lt;UserControl x:Class="ExternalDataSourceComparison.ImportedInfoGrid"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
           mc:Ignorable="d" 
           d:DesignHeight="300" d:DesignWidth="300"
           Height="Auto" Width="Auto"&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;DataGrid Name="_dataGrid" Grid.Row="0"&gt;
          &lt;DataGrid.Columns&gt;
              &lt;DataGridTextColumn Binding="{Binding Path[0].Length}"/&gt;
          &lt;/DataGrid.Columns&gt;
      &lt;/DataGrid&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have the <code>UserControl</code> in my <code>MainWindow</code> that looks like this:</p>
  
  <pre><code>&lt;Window x:Class="ExternalDataSourceComparison.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:ExternalDataSourceComparison"
      Title="MainWindow" Height="350" Width="525" WindowState="Maximized"&gt;
  &lt;Grid&gt;
      &lt;Grid.RowDefinitions&gt;
          &lt;RowDefinition/&gt;
          &lt;RowDefinition Height="Auto"/&gt;
      &lt;/Grid.RowDefinitions&gt;
      &lt;local:ImportedInfoGrid x:Name="ExternalData" Grid.Row="0"/&gt;
      &lt;StackPanel Height="36px" Orientation="Horizontal" Grid.Row="1"&gt;
          &lt;Button Name="_import" Content="Import Data" Margin="5" Padding="5, 2" Click="Import_Click"/&gt;
          &lt;Button Name="_compare" Content="Compare" Margin="5" Padding="5, 2" Click="Compare_Click"/&gt;
          &lt;Button Name="_cancel" Content="Cancel" Margin="5" Padding="5, 2" Click="Cancel_Click"/&gt;            
      &lt;/StackPanel&gt;
  &lt;/Grid&gt;
  </code></pre>
  
  <p></p>
  
  <p>In my code behind for the window using the method <code>fs.CSVToStringArray</code>, I open up a CSV file and parse out the contents to a <code>string[][]</code> the outer array represents the rows and the inner array are all of the columns so string[0][3] would be row 1 column 4.</p>
  
  <p>In my code behind I just set <code>ItemsSource</code> equal to the array of arrays as shown below:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Data;
  using System.Windows.Documents;
  using System.Windows.Input;
  using System.Windows.Media;
  using System.Windows.Media.Imaging;
  using System.Windows.Navigation;
  using System.Windows.Shapes;
  using System.Data;
  
  namespace ExternalDataSourceComparison
  {
      /// &lt;summary&gt;
      /// Interaction logic for MainWindow.xaml
      /// &lt;/summary&gt;
      public partial class MainWindow : Window
      {
          FileStuff fs = new FileStuff();
          public MainWindow()
          {
              InitializeComponent();
          }
  
          private void Import_Click(object sender, RoutedEventArgs e)
          {
              string[][] array = fs.CSVToStringArray();
              this.ExternalData._dataGrid.ItemsSource = array;
          }
  
          private void Cancel_Click(object sender, RoutedEventArgs e)
          {
  
          }
  
          private void Compare_Click(object sender, RoutedEventArgs e)
          {
  
          }
      }
  }
  </code></pre>
  
  <p>The output is not what I expected at all though. I think it showing the attributes of the object instead of the actual content. Is there a way to automatically generate rows and columns or will I have to write the code to create the columns and build the rows? I thought with a <code>DataGrid</code> you could bind something like a <code>string[][]</code> or a <code>List&lt;string[]&gt;</code> to the <code>ItemsSource</code> and it would just generated columns. It is currently automatically generating columns, it just isn't filling them with the contents of the <code>string[][]</code>.</p>