views:

404

answers:

2

In a WPF datagrid is it possible to group column headings?

What I'm after is

| Column 1 | Column 2 | Column 3|
| a  b  c  | a  b  c  | a  b  c |
| z  x  y  | z  x  y  | z  x  y |

I've searched around and can't see an obvious way of doing this. I could use a templated column and then mimick the extra cells within the each template but that wouldn't work well for ordering etc.

I suppose all I'm saying it that I'm looking for is how people have managed to span column headings across multiple coluns.

Any help or ideas would be greatly appreciated.

A: 

Make a custom HeaderTemplate for your columns.

    <DataGrid>
        <DataGrid.Columns>
            <DataGridTextColumn>
                <DataGridTextColumn.HeaderTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock>Column 1</TextBlock>
                            <TextBlock>xyz</TextBlock>
                        </StackPanel>
                    </DataTemplate>
                </DataGridTextColumn.HeaderTemplate>
            </DataGridTextColumn>
            <DataGridTextColumn Header="Header" />
        </DataGrid.Columns>
    </DataGrid>
majocha
Thanks for your comment. I want a multi-column header as oppsed to a single column header sub divided.
Sam Brinsted
A: 

You might be better off removing the column headers and adding in your own outside the grid. There is a good post here that shows how to make a "header" that spans multiple columns.

ADurkin