views:

32

answers:

1

Hello,

I have to group the data int the datagrid. I have done following for that:

  1. Have added the style to resources as:
> <Style x:Key="GroupHeaderStyle"
> TargetType="{x:Type GroupItem}">
>         <Setter Property="Template">
>             <Setter.Value>
>                 <ControlTemplate TargetType="{x:Type GroupItem}">
>                     <Expander IsExpanded="False"
>                      >
>                         <Expander.Header>
>                             <TextBlock Text="{Binding Name}"/>
>                 </Expander.Header>
>                         <ItemsPresenter />
>                     </Expander>
>                 </ControlTemplate>
>             </Setter.Value>
>         </Setter>
>     </Style>
  1. I have applied the style as:
    <dg:DataGrid Grid.Row="1" Name="dgAuthor" HorizontalScrollBarVisibility="Hidden"
AutoGenerateColumns="False" RowHeaderWidth="17" RowHeight="25">
                <dg:DataGrid.GroupStyle>
                    <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                        <GroupStyle.Panel>
                            <ItemsPanelTemplate>
                                <dg:DataGridRowsPresenter/>
                            </ItemsPanelTemplate>
                        </GroupStyle.Panel>
                    </GroupStyle>
                </dg:DataGrid.GroupStyle>
           </dg:DataGrid>
  1. I have infoList as a ObservableCollection and have assigned it as itemssource as follows:

    ListCollectionView lcv = new ListCollectionView(infoList); lcv.GroupDescriptions.Add(new PropertyGroupDescription("Author")); dgAuthor.ItemsSource = lcv;

where Info is class which has Author,Book,Year properties.

I have to group the datagrid on Author property. I am able to display the explander but cannot see any rows in it. Can anybody tell me whats wrong with the code?

A: 

Setting AutoGenerateColumns="True" explicitely solves the problem. I also added the column definitions.

Archie