DataGridComboBoxColumn for a collection

Feb 1, 2010 at 3:00 PM
Edited Feb 1, 2010 at 7:03 PM

I have an object with a collection and am attempting to give the user a drop down for selecting one of the properties in that collection. I actually thought I had it working on my Vista machine but have copied the code to my XP machine at work and am now seeing a previous behavior that is not correct. I am using the latest "stable" release of the toolkit (3.5.40128.1).

The WPF form's DataContext is a ViewModel object (bookingViewModel in my terms). The bookingViewModel has an IList collection of animalViewModels (AnimalCollection). That collection contains what I expect. Each animalVM has a color property that needs to be chosen from a set list based on another property. Color is an object as well with ColorId as the key value. When I create the animalVM object the appropriate list of colors is retrieved and is correct. The WPF form has a datagrid which displays the animalViewModels correctly but the datagridcomboboxcolumn that should have the drop down list of colors will not behave correctly. Right now, I get the drop-down on the first item in the grid but none of the other rows have the list. I don't even get the arrow indicating that the column is a drop down in those rows.

What am I missing to get the grid rows to understand that all the rows need the drop-down?

The pertinent code for the datagrid is below.

                <toolkit:DataGrid Name="dataGridBookingAnimal" ItemsSource="{Binding AnimalCollection}" 
                                  AutoGenerateColumns="False"
                                  Style="{StaticResource dataGridStyle}"
                                  CellStyle="{StaticResource dgCellStyleNoCancel}"
                                  Margin="10,0,9,29"
                                  HorizontalContentAlignment="Left"
                                  RowDetailsVisibilityMode="Collapsed"
                                  SelectionMode="Single" CanUserReorderColumns="False" CanUserAddRows="False"
                                  ColumnHeaderHeight="24" Height="126" VerticalAlignment="Bottom"
                                  RowHeight="20">
                    <toolkit:DataGrid.Columns>
                        <toolkit:DataGridTextColumn Binding="{Binding BookingSuffix}" Header="#"
                                                    MinWidth="10" Width="20" IsReadOnly="True" />
                        <toolkit:DataGridTextColumn Binding="{Binding Gender}"
                                                        Header="Gender"
                                                        MinWidth="10" Width="60" IsReadOnly="True" />
                        <toolkit:DataGridComboBoxColumn Width="90" Header="Color"
                                                        SelectedItemBinding="{Binding Color.ColorId}"
                                                        SelectedValueBinding="{Binding Color}"
                                                        DisplayMemberPath="ColorDescription">
                            <toolkit:DataGridComboBoxColumn.ElementStyle>
                                <Style TargetType="{x:Type ComboBox}">
                                    <Setter Property="ItemsSource" Value="{Binding Path=BreedColors}"/>
                                </Style>
                            </toolkit:DataGridComboBoxColumn.ElementStyle>
                            <toolkit:DataGridComboBoxColumn.EditingElementStyle>
                                <Style TargetType="{x:Type ComboBox}">
                                    <Setter Property="ItemsSource" Value="{Binding Path=BreedColors}"/>
                                    <Setter Property="IsEditable" Value="True"/>
                                    <Setter Property="StaysOpenOnEdit" Value="True"/>
                                </Style>
                            </toolkit:DataGridComboBoxColumn.EditingElementStyle>
                        </toolkit:DataGridComboBoxColumn>
                    </toolkit:DataGrid.Columns>
                </toolkit:DataGrid>
(Added note: The behavior appears to work correctly if the records are not new. That is, if I add records; persist them with no color; edit the color id
 in the database to an appropriate id; run the form; the drop down appears for all records and I can change it appropriately.)