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 ?