5

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

HaxElit
  • 3,983
  • 7
  • 34
  • 43

1 Answers1

15

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
  • 23,555
  • 29
  • 141
  • 228
  • 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 Dec 15 '09 at 18:32
  • 1
    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 Dec 18 '09 at 00:51
  • 3
    Do you know if it is possible to have the comboBox visible even in ViewMode. I want my users to know that, that's a ComboBox – MBen Oct 05 '11 at 06:44