ADO Entity Framework 4 to WPF Datagrid. DatagridComboBox nightmare
The WPF datagrid -seems- like it's going to work, but the combobox implementation does not work straight from the designer. So I'm left wandering around in the XAML randomly changing things trying to get it to work.
The problems are numerous. I want to display a foreign key relationship (with drop down) instead of a bunch of numbers for a selection. It seems like it shouldn't be this hard.
I can get the right values to show up (their descr开发者_开发知识库iption instead of an ID), but the table freaks out thinking that all the values have been modified. If I select a drop down, it refuses to allow me to edit anything else.
I want to chalk this up as a .NET bug, but since I'm new to WPF datagrids, it's probably just me. Here is the code.
<DataGridComboBoxColumn Header="Make Up" ItemsSource="{Binding Source={StaticResource materialMakeUpTypesViewSource}}"
DisplayMemberPath="Description" TextBinding="{Binding Path=MaterialMakeUpType.Description}"
SelectedItemBinding="{Binding Path=MaterialMakeUpType.Description}" SelectedValueBinding="{Binding Path=MaterialMakeUpType.ID}" />
This was just confusing because of the different options.
ItemSource was right. DisplayMemberPath, right. TextBinding wasn't needed and actually caused a lot of visual artifacts. SelectedItemBinding wasn't needed. I had to add a SelectedValuePath.
Anyway, this works as intended.
<DataGridComboBoxColumn Header="Make Up" ItemsSource="{Binding Source={StaticResource materialMakeUpTypesViewSource}}"
SelectedValuePath="ID"
DisplayMemberPath="Description"
SelectedValueBinding="{Binding Path=makeup}" />
精彩评论