Click here to Skip to main content
15,910,303 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a datagridtemplatecolumn with a grouped combobox on it. The items are displayed correctly, but the headers are not, actually a blank space appears.

I changed the Header field to match the same as the displayed data and the header still appears empty. Is there a different binding in the headertemplate than in the itemtemplate?

The Combobox is binded to a listcollection view with two fields: Bienes_ID and TipoBienes_ID with grouping on TipoBienes_ID.

The main datagrid is binded to a dataview with several fields, including Bienes_ID.



XML
<DataGridTemplateColumn x:Name="ColumnaCombo">
                      <DataGridTemplateColumn.CellTemplate >
                          <DataTemplate >
                              <TextBlock Text="{Binding Path=Bienes_ID}"></TextBlock>
                          </DataTemplate>
                      </DataGridTemplateColumn.CellTemplate>
                      <DataGridTemplateColumn.CellEditingTemplate >
                          <DataTemplate >
                              <ComboBox x:Name="ComboBienesAgrupados"  SelectedValuePath="Bienes_ID" ItemsSource="{Binding Path=ListaBienes, RelativeSource={RelativeSource AncestorType=Window},UpdateSourceTrigger=PropertyChanged }" SelectedValue="{Binding Bienes_ID}"  >
                                  <ComboBox.GroupStyle >
                                      <GroupStyle>
                                          <GroupStyle.HeaderTemplate>
                                              <DataTemplate >
                                                  <TextBox   Text="{Binding  Path =Bienes_ID }" Background ="AliceBlue" ></TextBox>
                                              </DataTemplate>
                                          </GroupStyle.HeaderTemplate>
                                      </GroupStyle>
                                  </ComboBox.GroupStyle>
                                  <ComboBox.ItemTemplate >
                                      <DataTemplate >

                                          <TextBlock Text="{Binding Path=Bienes_ID}"></TextBlock>
                                      </DataTemplate>
                                  </ComboBox.ItemTemplate>
                              </ComboBox>
                          </DataTemplate>
                      </DataGridTemplateColumn.CellEditingTemplate>
                  </DataGridTemplateColumn>


What I have tried:

I managed to show in the itemtemplate the fields TipoBienes_ID, so only the headertemplate is not binding correctly.
Posted
Updated 21-Jun-16 4:34am

1 solution

Apparently there is a trick, in the header I am not binding against a data object from my dataview. Instead I am binding against PropertyGroupDescription object. So instead of binding to TipoBienes_ID I had to Bind to the PropertyGroupDescription.name property like this:

XML
<combobox.groupstyle>
    <groupstyle>
          <groupstyle.headertemplate>
               <datatemplate>
                   <textbox text="{Binding  Path =Name}" background="AliceBlue"></textbox>
               </datatemplate>
          </groupstyle.headertemplate>
    </groupstyle>

</combobox.groupstyle>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900