HaxElit
HaxElit

Reputation: 4073

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

Upvotes: 5

Views: 9753

Answers (1)

Aran Mulholland
Aran Mulholland

Reputation: 23945

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

Upvotes: 15

Related Questions