2

I am creating a WPF DataGrid dynamically through code. One of the columns has to be of type ComboBox

public class myModel
{
    public  string[] item;
}   

var modelList = new List<myModel>();
modelList.Add(new myModel {item = new string[] {"One", "Two", "Three"}});
modelList.Add(new myModel {item = new string[] {"1", "2", "3"}});

foreach (DataColumn col in myData.Columns)
{
    if (col.ColumnName.Equals("Model"))
    {
        var binding = new Binding("modelList");
        binding.Source = modelList;

        myGrid.Columns.Add(new DataGridComboBoxColumn
        {
            Header = col.ColumnName,
            Width = 75,
            ItemsSource =modelList, //new string[] { "4", "5", "6" } <-this only works!
            DisplayMemberPath = "item",
            SelectedItemBinding = binding,
            SelectedValuePath = "item"
        });
    }
}

I have really no idea what's going on . All I have after this is an empty ComboBox. What I need is first combo to have {"One", "Two", "Three"}, 2nd combo {"1", "2", "3"} etc. I can't use model behind this because the number of columns varies.

How can I achieve this ?

alexo
  • 936
  • 8
  • 16
Jalle
  • 1,566
  • 5
  • 22
  • 42
  • possible duplicate of [How do I bind a WPF DataGrid to a variable number of columns?](http://stackoverflow.com/questions/320089/how-do-i-bind-a-wpf-datagrid-to-a-variable-number-of-columns) – pquest Dec 15 '14 at 16:34

0 Answers0