0

I have a WPF datagrid inside a UserControl. I have a ComboBox column in the datagrid to load data from database, which is loading well. I again added a ComboBox in the Header with same data (my ultimate goal is, I want to make all the rows Selected with same Header ComboBox selected value).

But the ComboBox in the Header is not getting the DataContext and it is empty.

<DataGridTemplateColumn>
    <DataGridTemplateColumn.HeaderTemplate>
        <DataTemplate>
            <ComboBox Grid.Row="1" Width="100" HorizontalAlignment="Center" Name="workGroupHeaderSelect"  
                      ItemsSource="{Binding Path=WorkstationGroups}"  SelectedValuePath="ID"
                      DisplayMemberPath="Name">
            </ComboBox>
        </DataTemplate>
    </DataGridTemplateColumn.HeaderTemplate>

    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox SelectionChanged="WorkGroupSelect_OnSelectionChanged" Grid.Row="1" Width="100" HorizontalAlignment="Center" Name="workGroupSelect"  
                      ItemsSource="{Binding Path=WorkstationGroups}" 
                      SelectedValuePath="ID"
                      DisplayMemberPath="Name">
            </ComboBox>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

Grid column

What I am missing here?

My datagrid is inside a User Control.

Viyan
  • 1
  • 3
  • Can you share the model structure you're using? `WorkstationGroups` is static list or values can be different for each rows? – dhilmathy Aug 30 '18 at 22:18
  • Possible duplicate of [Binding DataGrid column Header to DataContext](https://stackoverflow.com/questions/8891560/binding-datagrid-column-header-to-datacontext) – Bizhan Aug 30 '18 at 23:10
  • @dhilmathy WorkstationGroups is a static list. It won't change! public List WorkstationGroups { get; set; } – Viyan Aug 31 '18 at 14:23

0 Answers0