tags:

views:

197

answers:

1

Hi All, I want to display a dropdown in the datagrid with different values the user can select from. Somehow I am not able to display a ComboBox, instead it just displays the value as if it were a normal TextColumn. Below is my code,

<StackPanel Grid.Row="0">
            <toolkit:DataGrid Name="definitionGrid" Margin="0,10,0,0" AutoGenerateColumns="False" 
                                              CanUserAddRows="False" CanUserDeleteRows="False" IsReadOnly="True"
                                              RowHeight="25" FontWeight="Normal" ItemsSource="{Binding Profile}"
                                              SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Auto" Width="450"
                              ScrollViewer.VerticalScrollBarVisibility="Auto" Height="200">
                <toolkit:DataGrid.Columns>
                    <toolkit:DataGridTextColumn Header="Name" Width="80" Binding="{Binding Name}" CellStyle="{StaticResource cellCenterAlign}"/>
                    <toolkit:DataGridComboBoxColumn Header="Gender" Width="220" SelectedItemBinding="{Binding Gender}" ItemsSource="{Binding Source={StaticResource GenderValues}}" CellStyle="{StaticResource cellCenterAlign}"/>
                    <toolkit:DataGridCheckBoxColumn Header="Email" Width="60" Binding="{Binding ReceivesEmail}" CellStyle="{StaticResource cellCenterAlign}"/>
                    <toolkit:DataGridTextColumn Header="Others" Width="80" CellStyle="{StaticResource cellCenterAlign}"/>
                </toolkit:DataGrid.Columns>
            </toolkit:DataGrid>   
       </StackPanel>
+3  A: 

The DataGridComboBoxColumn only displays ComboBox if it is in edit mode; else it displays like an ordinary DataGridTextColumn. If you want to display a ComboBox you could define a DataGridTemplateColumn:

<DataGridTemplateColumn Header="Gender">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox Width="220" SelectedItem="{Binding Gender}" ItemsSource="{Binding Source={StaticResource GenderValues}}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>