I´m trying to bind Data to a DataGridComboBoxColumn.
I already managed to bind the ItemsSource, but the bound value won´t be selected, instead the ComboBox has just nothing selected.
DataGrid:
<DataGrid x:Name="dg" ItemsSource="{Binding}" AutoGenerateColumns="false">
<DataGrid.Columns>
<DataGridComboBoxColumn Header="Name" SelectedValueBinding="{Binding name}" ItemsSource="{Binding Source={x:Static K:Material.loadedMaterials}}" DisplayMemberPath="name"/>
<DataGridTextColumn Header="Name2" Binding="{Binding name}"/>
</DataGrid.Columns>
</DataGrid>
Material-Class:
public class Material {
public static List<Material> loadedMaterials;
static Material() {
loadedMaterials = new List<Material>();
loadedMaterials.Add(new Material("TEST1", "", ""));
loadedMaterials.Add(new Material("TEST2", "", ""));
loadedMaterials.Add(new Material("TEST3", "", ""));
}
public string name { get; set; }
public string name2 { get; set; }
public string name3 { get; set; }
public Material(string n, string n2, string n3) {
name = n;
name2 = n2;
name3 = n3;
}
}
Main Window:
public partial class MainWindow : Window {
public System.Collections.ObjectModel.ObservableCollection<Material> mat;
public MainWindow() {
InitializeComponent();
mat = new System.Collections.ObjectModel.ObservableCollection<Material>();
mat.Add(new Material("TEST1", "TEST1", "TEST1"));
dg.DataContext = mat;
}
}
As you can see here, the DropDown is loaded and the Textbox, which has the same data bound, shows it correctly, but the ComboBox is empty.
I´m excpecting TEST1
to be selected and displayed in the ComboBox.