开发者

ADO Entity Framework 4 to WPF Datagrid. DatagridComboBox nightmare

开发者 https://www.devze.com 2022-12-29 23:32 出处:网络
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 t

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}" />   
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号