I'm writing an import utility, I'd like for users to be able to upload from a CSV and then direct the columns where they'd like them to go.
So in order to do this, I'm making the header of each column a ComboBox populated with all of the possible columns.
xaml
<DataGrid x:Name="ImportTable"
ItemsSource="{Binding displayTable}"
AutoGeneratingColumn="OnAutoGeneratingColumn"
AutoGenerateColumns="True"
CanUserAddRows="True"
CanUserDeleteRows="True"
EnableColumnVirtualization="True"
EnableRowVirtualization="True"
MaxWidth="1300"
MaxHeight="600"
/>
xaml.cs
private void OnAutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
var cb = new ComboBox();
foreach (DataColumn test in (DataContext as EnterValueDialogViewModel).displayTable.Columns)
Console.Out.WriteLine(test);
cb.ItemsSource = (DataContext as EnterValueDialogViewModel).displayTable.Columns;
e.Column.Header = cb;
}
This correctly prints out all of the columns, but nothing is actually displayed inside of the combo box's
The combobox now displays properly in the dropdown. but i can't get it's selectedValue to set. The following code prints out that the selectedvalue is correct, but it's still populating initially as blank/unselected
var cb = new ComboBox();
cb.DisplayMemberPath = "ColumnName";
cb.SelectedValue = e.PropertyName.ToString();
cb.ItemsSource = (DataContext as EnterValueDialogViewModel).displayTable.Columns;
Console.Out.WriteLine(cb.SelectedValue);
e.Column.Header = cb;
DisplayMemberPath
property for your combobox? To me it looks like you may have items, those items are just displayed as blanks. – Sudsy1002