title: Why is AutoGeneratingColumn filling every dropdown list with that of final column?
body: <p>I am trying to make an auto-generated GridView that will put an editable ComboBox in each cell in each column that contains strings. The selectable items for each column should match the values that are already in that column in the DataTable. The code below almost achieves this, but for some reason, it fills the drop-down list for every column with the drop-down list for the final column.</p>
  
  <pre><code>    private void dataGrid_AutoGeneratingColumn(object sender, 
          DataGridAutoGeneratingColumnEventArgs e) {
          if (e.PropertyType == typeof(string)) {
              DataGridTemplateColumn comboColumn = new DataGridTemplateColumn();
              comboColumn.Header = e.PropertyName;
              comboColumn.CellTemplate = (DataTemplate)Resources["ComboBoxDataTemplate"];
              FrameworkElementFactory comboBoxFactory = new FrameworkElementFactory(typeof(ComboBox));
              List&lt;string&gt; list = (DataContext as MainVM).PartClassVM.DataTable.AsEnumerable()
                  .Select(row =&gt; row[e.PropertyName].ToString()).Distinct().ToList&lt;string&gt;();
              comboBoxFactory.SetValue(ComboBox.ItemsSourceProperty, list); 
              comboColumn.CellTemplate.VisualTree = comboBoxFactory;
              e.Column = comboColumn;
          }
      }
  </code></pre>
  
  <p>Can anyone explain why this is happening, and how to get around it? Thanks in advance.</p>