0

示されているように、 DataGridで定義されたComboBoxがあります。ComboBoxのは、プロパティを含むカスタム クラスのリストです。はプロパティで、はプロパティです。はDataGridのプロパティにバインドされています。( DataGridの はビューであることに注意してください。) ComboBoxは適切に設定され、 ComboBox選択のプロパティへのバインドも同様に機能します。すべて問題なく、新しいデータに適しています。問題は、の既存のデータにあります。ItemsSourceCodePickListNameIDDisplayMemberPathNameSelectedValuePathIDSelectedValueGLCode ItemsSourceItemsSourceGLCodeItemsSourceデータグリッド。ComboBox のテキストブロックは単に空白です。ComboBox ItemsSource が読み込まれると、ComboBoxDataGridのプロパティとComboBoxGLCodeのプロパティを一致させることができないようです。これらのプロパティは同じタイプです。WinForms はこのシナリオを処理しますが、WPF で動作させることはできません。 ItemsSourceID ItemsSource

<DataGrid ItemsSource="{Binding EntityDetailsView.View}">
    <DataGrid.Columns>
        <DataGridTemplateColumn>
             <DataGridTemplateColumn.CellTemplate>
                 <DataTemplate>
                        <ComboBox ItemsSource="{BindingPath=DataContext.CodePickList, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
                                  DisplayMemberPath="Name" SelectedValuePath="ID" SelectedValue="{Binding GLCode, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
                                  IsEditable="False" IsReadOnly="False"/>
                 </DataTemplate> 
             </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
4

1 に答える 1

0

DataGrid の ItemsSource の GLCode は、データベースから (Entity Framework を介して) 固定長の文字列 (右詰め) として取得されていることがわかります。ComboBox の ItemsSource の ID は、通常の C# 文字列でした。したがって、値が一致せず、既存のデータが表示されませんでした。解決策は、ComboBox ItemsSource に ID 文字列を埋め込むことでした。ComboBox が期待どおりに機能するようになりました。

于 2013-04-05T13:45:25.040 に答える