views:

805

answers:

1

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

+3  A: 

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

Aran Mulholland
You would not believe HOW hard this has been to find. I didn't know the non edit mode state still had a combo box in it. I thought it was just a textblock.Thanks again!
HaxElit
yep its a bit wierd. i've found working through the code for the datagrid really lets you in on a few tricks. the code to look at is the GenerateElement function in the DatagridComboColumn, they have a display only combo box. I import the datagrid sources into my project and when i am finished i replace it with a straight dll reference.
Aran Mulholland