DataGridComboBoxColumn with bound members

Aug 22, 2008 at 3:40 PM
Hello

I need in a column of a datagrid a combobox to lookup values from another table. Therefore I would like to use a construct like this:

        <dg:DataGrid x:Name="DG" ItemsSource="{Binding}" AutoGenerateColumns="False"  >
            <dg:DataGrid.Columns>
                <dg:DataGridComboBoxColumn x:Name="ColFig"  
                                           DataFieldBinding="{Binding Path=Xxx_id}"
                                           DisplayMemberPath = "TextValue"
                                           SelectedValuePath = "Id" >
                </dg:DataGridComboBoxColumn>
            </dg:DataGrid.Columns>
        </dg:DataGrid>


and in the code:

        ColFig.ItemsSource = From f In DB.TFigures Select f    ' delivers ID and TextValue pairs
        DGF.ItemsSource = From x In DB.Txxx Select x          


Unfortunately there is no DisplayMemberPath and SelectedValuePath.
How could be done that?

Thanks
Peter
Coordinator
Aug 26, 2008 at 9:23 PM
I just wrote a sample for it here, http://blogs.msdn.com/vinsibal/archive/2008/08/26/wpf-datagrid-working-with-datagridcomboboxcolumn.aspx.  Hope that helps.
Aug 28, 2008 at 7:31 AM
Thanks a lot. It's a good hint in the right direction. But the Northwind database is not the best sample-DB. Usually we use a guid or at least an integer as key. Suchg keys will usually never shown to users.
I would like to see some other fields from the Customer's table, for example "CompanyName", in the combobox as well as in the grid column.
I could successfully load the data for the combobox but not for the grid (cells in non-editing mode)
Coordinator
Aug 28, 2008 at 3:00 PM
Here are a couple possible solutions for it, http://blogs.msdn.com/vinsibal/archive/2008/08/28/wpf-datagrid-working-with-datagridcomboboxcolumns-part-2.aspx.