Grouping in datagrid - rows not getting displayed
Posted
by Archie
on Stack Overflow
See other posts from Stack Overflow
or by Archie
Published on 2010-05-05T14:11:10Z
Indexed on
2010/05/06
4:08 UTC
Read the original article
Hit count: 369
Hello,
I have to group the data int the datagrid. I have done following for that:
- 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>
- 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>
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?
© Stack Overflow or respective owner