There are 2 issues you might be referring to.
First one is that setting dgcbc.ItemsSource = columnList is not enough to make ComboBox display list of items to choose from.
Depending on the type of columnList you need to set DisplayMemberPath and SelectedValuePath properties, for example:
var columnList = new Dictionary<string, string>
{
{ "123", "test 123" },
{ "aaa", "test aaa" },
{ "qwe", "test qwe" }
};
dgcbc.ItemsSource = columnList;
dgcbc.DisplayMemberPath = "Key";
dgcbc.SelectedValuePath = "Value";
Another issue is binding of the column to the ItemsSource which is set on your DataGrid object(s).
dg2.ItemsSource = dt;
dgcbc.TextBinding = new Binding(string.Format("[{0}]", "Column_Name");
You might also wonder how to display text in DataGridTextColumn:
dgtc.Binding = new Binding(string.Format("[{0}]", "Column_Name");
I am unsure if this is what you want to achieve for column mapping, probably you would like to modify a header template of the grid and present the grid data as text below. To do this use DataGridTemplateColumn DataGridTextColumn column with both header Label and ComboBox in it's header.
hope it helps.
Edit:
I prepared a quick and dirty code only solution.
XAML:
<DataGrid x:Name="dg" Grid.Row="0" AutoGenerateColumns="False"/>
Code behind:
// data is a rough equivalent of DataTable being imported
var data = new List<Dictionary<string, string>>
{
new Dictionary<string, string> { { "column1", "asd asfs af" }, { "column2", "45dfdsf d6" }, { "column3", "7hgj gh89" } },
new Dictionary<string, string> { { "column1", "aaasdfda" }, { "column2", "45sdfdsf 6" }, { "column3", "78gh jghj9" } },
new Dictionary<string, string> { { "column1", "s dfds fds f" }, { "column2", "4dsf dsf 56" }, { "column3", "78gh jgh j9" } },
};
// a list of columns to map to
var importToColumns = new List<string>
{
"123",
"aaa",
"qwe",
"456",
"bbb"
};
importMappings = new Dictionary<string, int>();
foreach(var column in data[0])
{
importMappings.Add(column.Key, -1);
}
foreach(var r in importMappings)
{
var dgtc = new DataGridTextColumn();
dgtc.Binding = new Binding(string.Format("[{0}]", r.Key));
var sp = new StackPanel();
dgtc.Header = sp;
sp.Children.Add(new Label { Content = r.Key });
var combo = new ComboBox();
sp.Children.Add(combo);
combo.ItemsSource = importToColumns;
var selectedBinding = new Binding(string.Format("[{0}]", r.Key));
selectedBinding.Source = importMappings;
combo.SetBinding(Selector.SelectedIndexProperty, selectedBinding);
dgtc.MinWidth = 100;
dgtc.CanUserSort = false;
dg.Columns.Add(dgtc);
}
dg.ItemsSource = data;
}
private Dictionary<string, int> importMappings;
After selection has been approved, importMappings will contain a list of mappings of columns - for each import file column it will contain an index of element in importToColumns list or -1 if no elements were selected.