title: How to display a List of Strings as a DataGrid (table) in XAML and C#
body: <p>I've been a long time lurker on SO and have only recently decided to set up an account. I've been spending quite a lot of hours trying to solve this problem I've been having without asking but I here it is. </p>
  
  <p>What I'm trying to accomplish: </p>
  
  <p>I have a list of strings, e.g: Mango, Banana, Melon (let's call it fruits) and I want to display it as a table in XAML (WPF), where it appears as row values on the left side, and the right side will be combo boxes that will allow users to pick a value. I'm currently stuck on the displaying part of this problem. I decided to use a DataGrid to display the list, and the code behind will do the data bindings.</p>
  
  <p>Here's the XAML part of it:</p>
  
  <pre><code>&lt;DataGrid x:Name="FruitDataGrid" Height="265" VerticalAlignment="Center" Margin="-7,8,-2,-6" HorizontalAlignment="Left" Width="1188" AutoGenerateColumns="False"&gt; 
   &lt;!-- If AutoGenerateColumns was true only the length is displayed.--&gt;
           &lt;DataGrid.Columns&gt;
           &lt;DataGridTextColumn x:Name="fruitsDisplay" Header="Fruits" MinWidth="450" IsReadOnly="True" /&gt;
           &lt;DataGridComboBoxColumn Header="Number of Boxes" MinWidth ="200" CanUserResize="True" Width="*"&gt;&lt;/DataGridComboBoxColumn&gt;
    &lt;/DataGrid.Columns&gt;
  </code></pre>
  
  <p></p>
  
  <p>Code Behind so far has been really simple, and after many attempts this is the most recent one.</p>
  
  <pre><code>private void populateFruitList()
      {
          FruitDataGrid.DataContext = fruitDataTable;
          //Binds a datatable instance to the datagrid, does not display anything.
      }
  </code></pre>
  
  <p>What I've been attempting:</p>
  
  <p>Turn the List of Strings into an Observable Collection, or Enumerable, and do FruitDataGrid.itemsource = fruitsObservable;</p>
  
  <p>The above method works, except that it will only display the length of each string value (if autogeneratecolumns is true), which is not what I want. If autogeneratecolumns was false then I can see the rows being shown, but not the string values. </p>
  
  <p>I also tried using DataView or DataGridView but I failed to define it in the XAML, VS2012 says that there isn't such a thing. </p>
  
  <p>I've been trying to do data binding as well as the <a href="https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh464965.aspx" rel="nofollow">MSDN Article</a> says, but VS2012 never manages to bind to the list properly.</p>
  
  <p>I then attempted to change my list into a datatable and [use a datagridview as specified here but again the XAML tells me it is not a valid class][2]. I am also aware of the performance impact datagridview might have but at this point I just want to display a table really. </p>
  
  <p>I've also seen that some tutorials use a DataGrid.datasource method but that isn't in the DataGrid I want, I think it's a different class? (the DataGrid I am attempting to use is System.Windows.Controls.DataGrid, and the other one is in Windows Forms [As shown here][3])</p>
  
  <p>Thanks again for taking the time to look into this. </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Trying to bind to the list in XAML this way:</p>
  
  <pre><code>&lt;DataGrid x:Name="FruitDataGrid" Height="265" VerticalAlignment="Center" Margin="-7,8,-2,-6" HorizontalAlignment="Left" Width="1188" AutoGenerateColumns="False" ItemsSource="fruitDataList"&gt; 
  </code></pre>
  
  <p>I get the error in XAML "The type converter for IEnumerable does not support converting from a string" which I think is because I'm doing it wrong. The table now shows a lot of empty rows though. </p>
  
  <p>Trying ItemSource="{Binding fruitDataList}" (where fruitDataList is a List) yields a blank table, and an error in VS for BindingExpression path error.</p>