views:

806

answers:

1

I have a WPF toolkit DataGrid as the dropdown in a ComboBox template.

<toolkit:DataGrid x:Name="InnerGrid"
                  ItemsSource="{TemplateBinding ItemsSource}" 
                  CanUserReorderColumns="False" CanUserResizeColumns="True" 
                  CanUserSortColumns="False" CanUserResizeRows="False" 
                  AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False">
    <toolkit:DataGrid.Columns>
        <toolkit:DataGridTextColumn Header="Account" Binding="{Binding Name}" IsReadOnly="True" />
        <toolkit:DataGridTextColumn Header="Description" Binding="{Binding Description}" IsReadOnly="True" />
    </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

When I select a value using the DataGrid in the dropdown, the selected item shows as highlighted in the DataGrid. When I set the selected value of the ComboBox programmatically or by using the arrow keys when the dropdown is closed, the selected item won't highlight in the DataGrid.

Is there some kind of binding I need to do within the DataGrid to highlight the selected item?

As Chris Nicol mentioned, I did just need to add a binding to the SelectedItem of the ComboBox, in this case the TemplateBinding.

<toolkit:DataGrid x:Name="InnerGrid"
                  ItemsSource="{TemplateBinding ItemsSource}" 
                  SelectedItem="{TemplateBinding SelectedItem}"
                  CanUserReorderColumns="False" CanUserResizeColumns="True" 
                  CanUserSortColumns="False" CanUserResizeRows="False" 
                  AutoGenerateColumns="False" CanUserAddRows="False"
                  CanUserDeleteRows="False">
<snip>
+1  A: 

Sounds like you need to bind the selectedItem of the ComboBox to the SelectedItem of the DataGrid. Can you update the question to include the comboBox?

Chris Nicol
Sorry, I could have been more clear. It's actually a ComboBox template. You're right, I did just need to bind the SelectedItem.
a_hardin