Repeat DataGrid column headers in GroupHeader

Jan 25, 2009 at 12:59 PM
Hi,

I have been trying to find a way to repeat the column titles from my DataGrid in the group header, to no avail. Any ideas on how I can achieve this?

Thanks
Jan 25, 2009 at 8:05 PM
Hi,

 I had the same problem I managed to solve it by simply adding to the GroupTemplate a DataTemplate containing a grid. (bind the grid to the current Items Collection)
 It worked without a problem.

 If you don't manage I will post some code here for you.

Good day,
Calin
Jan 25, 2009 at 8:53 PM

Hi tanks for the answer! If you have the Example code can you pleas send it to me

Med vänliga hälsningar/Best regards

Boris Gasic

QSYS SVERIGE AB
Gnejsvägen 2, SE-553 02 JÖNKÖPING, SWEDEN
Phone: +46 36 440 15 00 Fax: +46 36 12 01 00
Direct: +46 36 440 15 03 Mobile: +46 701 427021

www.qsys.se

Från: Calin [mailto:notifications@codeplex.com]
Skickat: den 25 januari 2009 22:06
Till: Boris Gasic
Ämne: Re: Repeat DataGrid column headers in GroupHeader [wpf:45178]

From: Calin

Hi,

I had the same problem I managed to solve it by simply adding to the GroupTemplate a DataTemplate containing a grid. (bind the grid to the current Items Collection)

It worked without a problem.

If you don't manage I will post some code here for you.

Good day,

Calin

Read the full discussion online.

To add a post to this discussion, reply to this email (wpf@discussions.codeplex.com)

To start a new discussion for this project, email wpf@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Jan 27, 2009 at 5:36 AM
Thank you Calin,

I don't have this working yet, but I'll be trying again later today.


ChangedDaily
Jan 27, 2009 at 7:44 AM
Hi,

 It should go like this:

 <toolkit:DataGrid AutoGenerateColumns="True" 
                          Focusable="True">
            <toolkit:DataGrid.GroupStyle>
<GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <toolkit:DataGridRowsPresenter />
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander x:Name="Expand" IsExpanded="{Binding ElementName=_this, Path=IsExpanded}"
                                                  BorderBrush="#FFA4B97F" 
                                                  BorderThickness="0,0,0,1"
                                                  Loaded="Expand_Loaded">
                                            <Expander.Header>
                                                <DockPanel TextBlock.FontWeight="Bold">
                                                    <TextBlock>
                                                        <TextBlock x:Name="headerText" />
                                                        <TextBlock x:Name="headerName" Text="{Binding Path=Name}" Margin="5,0,5,0" />
                                                    </TextBlock>
                                                    <TextBlock>(
                                                        <TextBlock Text="{Binding Path=ItemCount}" />
                                                        <TextBlock Text="{Binding Path=ItemCount, Converter={StaticResource NumberToStringConverter}}" />
                                                        )
                                                    </TextBlock>
                                                </DockPanel>
                                            </Expander.Header>
                                            <toolkit:DataGrid HeadersVisibility="Column" AutoGenerateColumns="True"
                                              CanUserAddRows="False" CanUserDeleteRows="False" CanUserSortColumns="True" IsReadOnly="True"
                                              ItemsSource="{Binding Items}" />
                                        </Expander>

                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </toolkit:DataGrid.GroupStyle>

This groups items in a expander and inside in a new grid.
Let me know if it helped.

Regards,
Calin,
Jan 27, 2009 at 9:22 PM
Hi Calin,

Thanks for posting your code. It is almost identical to what I have! The difference I have with my code is that I have defined the group style in my usercontrol.resources because I want the user to have control over grouping, so I apply the style and group description from code. I think this is causing a problem with the CollectionViewGroup not containing anything when the template is first applied (no grouping exists at that time). If I disable AutoGenerateColumns and add the requried columns it works, but there is a short period after the expander is pressed while the grid is initialised where the DataGrid area just contains lots of horizontal lines.

Anyway, you've got me on the path to a solution so thanks again.

ChangedDaily.