locked
How to add footer in datagrid WPF RRS feed

Answers

All replies

  • AHOI

    Modify the style of the datagrid an a section ("footer") after the itemspresenter.

    Monday, May 3, 2010 6:32 AM
  • HI,

    <Grid>

     

     

    <dg:DataGrid Name="grdViewOrder" ItemsSource="{Binding}" AutoGenerateColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserSortColumns="False" CanUserAddRows="False" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="0,0,-9,0">

     

     

    <dg:DataGrid.Columns>

     

     

    <dg:DataGridTextColumn Width="Auto" Header="Quantity" Binding="{Binding Path=Quantity}" CanUserReorder="False" CanUserResize="False" IsReadOnly="True" />

     

     

    <dg:DataGridTextColumn Width="80" Header="Item" Binding="{Binding Path=ItemName}" CanUserReorder="False" CanUserResize="False" IsReadOnly="True" />

     

     

    <dg:DataGridTextColumn Width="80" Header="Item Price" Binding="{Binding Path=Price}" CanUserReorder="False" CanUserResize="False" IsReadOnly="True" />

     

     

    <dg:DataGridTextColumn Header="Total Price" Binding="{Binding Path=TotalPrice}" CanUserReorder="False" CanUserResize="False" IsReadOnly="True" Width="*" />

     

     

    </dg:DataGrid.Columns>

     

     

     

     

    </dg:DataGrid>

    <Grid>

    Can u please explain with an example?

    Thanks

    Monday, May 3, 2010 7:30 PM
  • You have to modify the control template of the datagrid to add in a footer row after the ItemsPresenter.  The itemspresenter is the object that outputs all the rows.  Then you would have to use valueconverters to perform the aggregations for the column.

    Here is an alternative method of using multiple datagrids.  example done with the datagrid from the toolkit:

    http://thibaud60.blogspot.com/2008/10/wpftoolkit-datagrid-with-footer-and.html

    and updated for 4.0

    http://thibaud60.blogspot.com/2010/02/footer-on-wpf-datagrid-by-use-several.html

    • Proposed as answer by Alexander Yudakov Tuesday, May 4, 2010 10:00 AM
    • Marked as answer by Jie Bao Monday, May 10, 2010 1:19 AM
    Tuesday, May 4, 2010 2:18 AM