title: wpf datagrid dynamic bound columns
body: <p>Let's assume there is the following class (for example purposes):</p>
  
  <pre><code>public class Item
  {
      public String Key {get;set;}
      public String[] Values { get; set;}
  }
  </code></pre>
  
  <p>for making it simple, imagine the length of each "Item"'s "Values" array is the same.
  Let's have a collection of these "Item"s:</p>
  
  <p>ExampleA:</p>
  
  <pre><code>List&lt;Item&gt; items = new List&lt;Items&gt;(
      new Item() { Key = "A", Values = new String[]{"OneA", null, "ThreeA"}},
      new Item() { Key = "B", Values = new String[]{"OneB", "TwoB", null}},
      new Item() { Key = "C", Values = new String[]{null, null, "ThreeC"}}
  );
  </code></pre>
  
  <p>ExampleB:</p>
  
  <pre><code>List&lt;Item&gt; items = new List&lt;Items&gt;(
      new Item() { Key = "1", Values = new String[]{"One1", null}},
      new Item() { Key = "2", Values = new String[]{"One2", "Two2"}},
      new Item() { Key = "3", Values = new String[]{null, null}}
  );
  </code></pre>
  
  <p>So how could I make a <code>DataGrid</code> from the ToolKit having the following columsn in the next cases:</p>
  
  <p>ExampleA:</p>
  
  <pre><code> A | OneA | ____ | ThreeA |
  
   B | OneB | TwoB | ______ |
  
   C | ____ | ____ | ThreeC |
  </code></pre>
  
  <p>ExampleB:</p>
  
  <pre><code> 1 | OneA | ____ |
  
   2 | OneB | TwoB |
  
   3 | ____ | ____ |
  </code></pre>
  
  <p>So, in words: in different cases the Values arrays have different length. But for one case all the Values arrays have the same length (for simplification).</p>
  
  <p>If <code>DataGridInstance.ItemsSource</code> is bound to items (<code>NotifyPropertyChanged</code> is implemented), how would the columns are set and how would the binding of the column values are set?</p>
  
  <p>Of course at every refresh <code>DataGridInstance.Columns.Clear()</code> is said.
  Than the columns are added again, the amount of them is well known (depends on the length of the "Values" array of course).</p>
  
  <p>But how I would create the binding of the values?</p>
  
  <p>I'd like to have something like the following:</p>
  
  <pre><code>Binding columnABinding = new Binding("Values[0]");
  Binding columnBBinding = new Binding("Values[1]");
  Binding columnCBinding = new Binding("Values[3]");
  </code></pre>
  
  <p>Uh, sorry for my bad english. I tried to keep it simple, hope it is understandable!
  Thank you for your answers in advance!</p>