Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGridComboBoxColumn

Hello I'm using the WPF DataGrid and I'm trying to get the ComboBox Column to work.

<tk:DataGridComboBoxColumn Header="GroupLevel"
                           DisplayMemberPath="Type"
                           SelectedItemBinding="{Binding Path=GroupLevel}"
                           >
    <tk:DataGridComboBoxColumn.EditingElementStyle>
        <Style TargetType="ComboBox">
            <Setter Property="ItemsSource" Value="{Binding Path=GroupLevel.Group.GroupLevels}" />
        </Style>
    </tk:DataGridComboBoxColumn.EditingElementStyle>

</tk:DataGridComboBoxColumn>

When I look at the grid, the column is blank, like its not using the display member path. But once I click in the column the combobox shows up and shows all the items in my ItemsSource and selects the proper one, so I know the bindings are all working correctly, even the DisplayMemberPath. Its just when I'm not editing the cell that it shows up blank.

Did I miss a property some where ?

Thanks, Raul

like image 799
HaxElit Avatar asked Dec 14 '09 19:12

HaxElit


1 Answers

im pretty sure that this is because when you are not in edit mode your Column does not have an items source and a ComboBox cant have a selected item without an items source. as soon as you go to edit mode your column gets its items source and everything is cool. you can fix this by specifying an items source like so :-

<tk:DataGridComboBoxColumn.ElementStyle>
    <Style TargetType="ComboBox">
        <Setter Property="ItemsSource" Value="{Binding Path=GroupLevel.Group.GroupLevels}" />
    </Style>
</tk:DataGridComboBoxColumn.ElementStyle>

then both your editing element and your (non-editing)element has the same ItemsSource

like image 181
Aran Mulholland Avatar answered Nov 03 '22 01:11

Aran Mulholland