This is a migrated thread and some comments may be shown as answers.

Printing of Grid view Does Not print the Total Summary

16 Answers 286 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Khurram Ilyas
Top achievements
Rank 1
Khurram Ilyas asked on 27 Sep 2010, 09:08 AM
I have added the Aggregate Sum Function in Girdview but when i print the Grid the last row that contain the total does not print.

Thanks,
-Saqib Ali 

16 Answers, 1 is accepted

Sort by
0
Khurram Ilyas
Top achievements
Rank 1
answered on 28 Sep 2010, 10:08 AM
I still not able to print the aggregate summary. Kindly let me know if anybody have done this

Thanks,
-Saqib ali
0
Vlad
Telerik team
answered on 30 Sep 2010, 11:30 AM
Hello,

 If your approach is similar to our demo you may need to copy columns aggregate functions as well since this is not included in the demo code:

foreach (GridViewDataColumn column in RadGridView1.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn newColumn = new GridViewDataColumn();
                newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
                grid.Columns.Add(newColumn);
            }

            foreach (GridViewDataColumn column in grid.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn currentColumn = column;

                GridViewDataColumn originalColumn = (from c in RadGridView1.Columns.OfType<GridViewDataColumn>()
                                                     where c.UniqueName == currentColumn.UniqueName
                                                        select c).FirstOrDefault();
                if (originalColumn != null)
                {
                    column.Width = originalColumn.ActualWidth;
                    column.DisplayIndex = originalColumn.DisplayIndex;

                    // copy original column aggregate functions here

                }
            }

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Khurram Ilyas
Top achievements
Rank 1
answered on 30 Sep 2010, 01:36 PM
Hi Vald,
    Thanks for your response but your are adding this as column if I am not wrong while summary of aggregate total is displayed as row . Can you provide with sample project. 

Thanks,
-Saqib Ali.
0
Vlad
Telerik team
answered on 30 Sep 2010, 02:29 PM
Hello,

If your approach is similar to our demo (print cloned grid) you need to copy all properties from the original grid. When you bind the cloned grid aggregates will be shown automatically. 

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Khurram Ilyas
Top achievements
Rank 1
answered on 01 Oct 2010, 08:35 AM
HI Vlad,

I am using Silverlight 3 with Rad Controls and the approach is similiar to your demo.

I have written the following code in btnPrint_Click after I got your response :

         offsetY = 0d;
            totalHeight = 0d;

            grid = new RadGridView();
            grid.DataContext = data.DataContext;
            grid.ItemsSource = data.ItemsSource;
            grid.RowIndicatorVisibility = Visibility.Collapsed;
            grid.ShowGroupPanel = false;
            grid.CanUserFreezeColumns = false;
            grid.IsFilteringAllowed = false;
            grid.AutoExpandGroups = true;
            grid.AutoGenerateColumns = false;

            foreach (GridViewDataColumn column in data.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn newColumn = new GridViewDataColumn();
                newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
                grid.Columns.Add(newColumn);
            }

            foreach (GridViewDataColumn column in grid.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn currentColumn = column;

                GridViewDataColumn originalColumn = (from c in data.Columns.OfType<GridViewDataColumn>()
                                                     where c.UniqueName == currentColumn.UniqueName
                                                     select c).FirstOrDefault();
                if (originalColumn != null)
                {
                    column.Width = originalColumn.ActualWidth;
                    column.DisplayIndex = originalColumn.DisplayIndex;

            // copy original column aggregate functions here

                    column.AggregateFunctions.Clear();
                    foreach (AggregateFunction func in originalColumn.AggregateFunctions)
                        column.AggregateFunctions.Add(func);
                }
            }

            //StyleManager.SetTheme(grid, StyleManager.GetTheme(data));

            //grid.SortDescriptors.AddRange(data.SortDescriptors);
            //grid.GroupDescriptors.AddRange(data.GroupDescriptors);
            //grid.FilterDescriptors.AddRange(data.FilterDescriptors);

            //ScrollViewer.SetHorizontalScrollBarVisibility(grid, ScrollBarVisibility.Hidden);
            //ScrollViewer.SetVerticalScrollBarVisibility(grid, ScrollBarVisibility.Hidden);

            //PrintDocument doc = new PrintDocument();

            //canvas = new Canvas();
            //canvas.Children.Add(grid);

            //doc.PrintPage += this.doc_PrintPage;
            //doc.Print("Print");

            grid.PrintToHtml();



      Kindly go through it once and please let me know about following things :

    1) Have I copied the aggregate functions correctly ?
    2) System.Windows.Printing  is not avaliable in Silverlight web project.


 Thanks,
-Saqib Ali
0
Vlad
Telerik team
answered on 01 Oct 2010, 10:06 AM
Hi,

 System.Windows.Printing is not available in Silverlight 3 - the only option is to use our old PrintToHtml() method if you do not want to upgrade your application. 

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Khurram Ilyas
Top achievements
Rank 1
answered on 07 Oct 2010, 12:41 PM
Hi Vlad,

I have upgraded my application to SIlverlight 4, However the issue is still unresolved.

1) The Print I have got still does not show the Aggregate Sum Function. I have also pasted my code in my last post and I am pasting it again.
Kindly check if I had copied the Aggregate Functions Correctly ? If not, kindly tell how to deal with the the Aggregate Functions ?

           offsetY = 0d;
            totalHeight = 0d;

            grid = new RadGridView();
            grid.DataContext = data.DataContext;
            grid.ItemsSource = data.ItemsSource;
            grid.RowIndicatorVisibility = Visibility.Collapsed;
            grid.ShowGroupPanel = false;
            grid.CanUserFreezeColumns = false;
            grid.IsFilteringAllowed = false;
            grid.AutoExpandGroups = true;
            grid.AutoGenerateColumns = false;

            foreach (GridViewDataColumn column in data.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn newColumn = new GridViewDataColumn();
                newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
                grid.Columns.Add(newColumn);
            }

            foreach (GridViewDataColumn column in grid.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn currentColumn = column;

                GridViewDataColumn originalColumn = (from c in data.Columns.OfType<GridViewDataColumn>()
                                                     where c.UniqueName == currentColumn.UniqueName
                                                     select c).FirstOrDefault();
                if (originalColumn != null)
                {
                    column.Width = originalColumn.ActualWidth;
                    column.DisplayIndex = originalColumn.DisplayIndex;

            // copy original column aggregate functions here

                    column.AggregateFunctions.Clear();
                    foreach (AggregateFunction func in originalColumn.AggregateFunctions)
                        column.AggregateFunctions.Add(func);

                }
            }

            StyleManager.SetTheme(grid, StyleManager.GetTheme(data));

            grid.SortDescriptors.AddRange(data.SortDescriptors);
            grid.GroupDescriptors.AddRange(data.GroupDescriptors);
            grid.FilterDescriptors.AddRange(data.FilterDescriptors);

            ScrollViewer.SetHorizontalScrollBarVisibility(grid, ScrollBarVisibility.Hidden);
            ScrollViewer.SetVerticalScrollBarVisibility(grid, ScrollBarVisibility.Hidden);

            PrintDocument doc = new PrintDocument();

            canvas = new Canvas();
            canvas.Children.Add(grid);

            doc.PrintPage += this.doc_PrintPage;
            doc.Print("Print");


2) Besides, the copying of grid to another has caused another problem i-e the Column Header in the printed grid is the name of the field in the object instead of what I defined in the Column Definition

e.g

        GridViewDataColumn c1 = new GridViewDataColumn() { Header = "Successful", DataMemberBinding = new Binding("SuccessCount") };
                c1.AggregateFunctions.Add(new SumFunction { Caption = "Total: ", SourceField = "SuccessCount" });
                this.data.Columns.Add(c1);

Now the printed grid shows "SuccessCount" in the Header instead of "Successful" and Aggregate Sum Function (Column Total) is NOT being shown.

Thanks,
Saqib Ali
0
Vlad
Telerik team
answered on 07 Oct 2010, 12:48 PM
Hi,

You've not copied the column headers nor ShowColumnFooters/ShowGroupFooters values from the original grid.

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Khurram Ilyas
Top achievements
Rank 1
answered on 07 Oct 2010, 01:50 PM
It's still not displaying the total find the attached picture. can you please provide the sample project. ?
0
Vlad
Telerik team
answered on 13 Oct 2010, 02:46 PM
Hi,

 We were able to reproduce this issue with our current official version. The group footers problem is already fixed and the fix is part of our latest build however we are still unsure what is causing the problem with column footers in this case. We are working currently on this and once we are ready we will provide more info/fix.

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vlad
Telerik team
answered on 17 Nov 2010, 01:37 PM
Hi,

 We believe that we've fixed these issues in our Q3 2010 release - let me know if you still have such issues.

Best wishes,
Vlad
the Telerik team
See What's New in RadControls for Silverlight in Q3 2010 on Tuesday, November 16, 2010 11:00 AM - 12:00 PM EST or 10:00 PM - 11:00 PM EST: Register here>>
0
Steve
Top achievements
Rank 1
answered on 05 Jun 2011, 07:28 PM
Version 2011.1.419.1040
The footer still does not show any values. Below is the code method for print.
Am I missing something, or is this not working in the gridview?

Attach is a image from the generated print and image of the orginial grid

public void Print(string Title)
    {
        offsetY = 0d;
        totalHeight = 0d;
        PrintGrid = new RadGridView();
        PrintGrid.FontSize = 12;
        PrintGrid.ItemsSource = OrgGrid.ItemsSource;
        PrintGrid.RowIndicatorVisibility = Visibility.Collapsed;
        PrintGrid.ShowGroupPanel = false;
        PrintGrid.CanUserFreezeColumns = false;
        PrintGrid.IsFilteringAllowed = false;
        PrintGrid.AutoExpandGroups = true;
        PrintGrid.AutoGenerateColumns = false;
        PrintGrid.ShowColumnFooters = OrgGrid.ShowColumnFooters;
        PrintGrid.ShowGroupFooters = OrgGrid.ShowGroupFooters;
        foreach (GridViewColumn column in OrgGrid.Columns)
        {
            GridViewColumn newColumn = (GridViewColumn)Activator.CreateInstance(column.GetType());
            newColumn.CopyPropertiesFrom(column);
            //if (column is GridViewDataColumn)
            //    (newColumn as GridViewDataColumn).DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
            foreach (AggregateFunction func in column.AggregateFunctions)
                newColumn.AggregateFunctions.Add(func);
              
            PrintGrid.Columns.Add(newColumn);
        }
        foreach (var item in OrgGrid.ChildTableDefinitions)
            PrintGrid.ChildTableDefinitions.Add(item);
        PrintGrid.HierarchyChildTemplate = OrgGrid.HierarchyChildTemplate;
        if (OrgGrid.ChildTableDefinitions.Any())
            PrintGrid.ExpandAllHierarchyItems();
        StyleManager.SetTheme(PrintGrid, StyleManager.GetTheme(OrgGrid));
        PrintGrid.SortDescriptors.AddRange(OrgGrid.SortDescriptors);
        PrintGrid.GroupDescriptors.AddRange(OrgGrid.GroupDescriptors);
        PrintGrid.FilterDescriptors.AddRange(OrgGrid.FilterDescriptors);
        ScrollViewer.SetHorizontalScrollBarVisibility(PrintGrid, ScrollBarVisibility.Hidden);
        ScrollViewer.SetVerticalScrollBarVisibility(PrintGrid, ScrollBarVisibility.Hidden);
        PrintDocument doc = new PrintDocument();
          
        StackPanel stackPanel = new StackPanel();
        stackPanel.Orientation = Orientation.Vertical;
        if (!string.IsNullOrEmpty(Title))
        {
            TextBlock textTitle = new TextBlock();
            textTitle.FontWeight = FontWeights.Bold;
            textTitle.Text = Title;
            stackPanel.Children.Add(textTitle);
        }
        stackPanel.Children.Add(PrintGrid);
        TextBlock textFooter = new TextBlock();
        textFooter.FontSize = 9.0;
        textFooter.Text = string.Format("Printed : {0}", DateTime.Now);
        stackPanel.Children.Add(textFooter);
        printCanvas = new Canvas();
        printCanvas.Children.Add(stackPanel);
        doc.PrintPage += this.doc_PrintPage;
        doc.Print(Title);
    }


Grid XAML
<telerik:RadGridView Name="gridIssueToIssue" 
                    AutoGenerateColumns="False"
                    HorizontalAlignment="Stretch" 
                    Margin="0"  
                    VerticalAlignment="Stretch"  
                    HorizontalContentAlignment="Stretch" 
                    VerticalContentAlignment="Stretch"  
                    telerik:StyleManager.Theme="Vista"
                    AlternationCount="2"
                                   
                    RowIndicatorVisibility="Collapsed" 
                    ShowColumnFooters="True"
                    telerikGridViewHeaderMenu:GridViewHeaderMenu.IsEnabled="True" >
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Company" DataMemberBinding="{Binding  Mode=OneWay, Path=CompanyName}" IsReadOnly="True"/>
        <telerik:GridViewDataColumn Header="Sales Rep" DataMemberBinding="{Binding Mode=OneWay, Path=EmployeeRep}" IsReadOnly="True"/>
        <telerik:GridViewDataColumn Header="Zone" DataMemberBinding="{Binding Mode=OneWay, Path=ZoneName}" IsReadOnly="True"/>
                          
        <telerik:GridViewDataColumn IsReadOnly="True" Header="Gross" DataMemberBinding="{Binding Gross, Mode=OneWay}" DataFormatString="c0" >
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction Caption="" ResultFormatString="{}{0:c}" SourceField="Gross" />
            </telerik:GridViewDataColumn.AggregateFunctions>
            <telerik:GridViewDataColumn.Footer>
                <StackPanel Orientation="Vertical" Margin="5,0">
                    <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center" Grid.Column="4">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </telerik:AggregateResultsList>
                </StackPanel>
            </telerik:GridViewDataColumn.Footer>
        </telerik:GridViewDataColumn>
  
        <telerik:GridViewDataColumn Header="Product" DataMemberBinding="{Binding Mode=OneWay, Path=AdType}" IsReadOnly="True"/>
  
        <telerik:GridViewDataColumn IsReadOnly="True" Header="Ad Size" DataMemberBinding="{Binding AdSizeName, Mode=OneWay}"  >
            <telerik:GridViewDataColumn.AggregateFunctions>
                <telerik:SumFunction Caption="" ResultFormatString="{}{0:n2}" SourceField="AdSize" />
            </telerik:GridViewDataColumn.AggregateFunctions>
            <telerik:GridViewDataColumn.Footer>
                <StackPanel Orientation="Vertical" Margin="5,0">
                    <telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center" Grid.Column="4">
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                                <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </telerik:AggregateResultsList>
                </StackPanel>
            </telerik:GridViewDataColumn.Footer>
        </telerik:GridViewDataColumn>
  
  
        <telerik:GridViewDataColumn Header="Position" DataMemberBinding="{Binding Mode=OneWay, Path=PositionName}" IsReadOnly="True"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>
0
Vlad
Telerik team
answered on 06 Jun 2011, 07:11 AM
Hi Steve,

 You can check the latest code of this demo here. I believe that this is caused by CopyPropertiesFrom() call - you can replace it with similar to our our demo code. 

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Steve
Top achievements
Rank 1
answered on 06 Jun 2011, 04:00 PM
I changed the code to be the same as the demo and no difference.

One think I noticed is that CopyPropertiesFrom, copies the header but not the footer, and if you manully copy the footer the PrintPage event errors on this line.
e.PageVisual = printCanvas;
Error:
    Value does not fall within the expected range.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.SetValue(IManagedPeerBase obj, DependencyProperty property, DependencyObject doh)
   at System.Windows.Printing.PrintPageEventArgs.set_PageVisual(UIElement value)
   at THMManager.Helpers.GridViewPrintExport.doc_PrintPage(Object sender, PrintPageEventArgs e)

Any more suggestions?


//foreach (GridViewColumn column in OrgGrid.Columns)
            //{
            //    GridViewColumn newColumn = (GridViewColumn)Activator.CreateInstance(column.GetType());
            //    newColumn.CopyPropertiesFrom(column);
  
            //    //if (column is GridViewDataColumn)
            //    //    (newColumn as GridViewDataColumn).DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
  
            //    foreach (AggregateFunction func in column.AggregateFunctions)
            //        newColumn.AggregateFunctions.Add(func);
  
            //    PrintGrid.Columns.Add(newColumn);
            //}
  
            foreach (GridViewDataColumn column in OrgGrid.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn newColumn = new GridViewDataColumn();
                newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
                PrintGrid.Columns.Add(newColumn);
            }
  
            foreach (GridViewDataColumn column in PrintGrid.Columns.OfType<GridViewDataColumn>())
            {
                GridViewDataColumn currentColumn = column;
  
                GridViewDataColumn originalColumn = (from c in OrgGrid.Columns.OfType<GridViewDataColumn>()
                                                     where c.UniqueName == currentColumn.UniqueName
                                                     select c).FirstOrDefault();
                if (originalColumn != null)
                {
                    column.Width = originalColumn.ActualWidth;
                    column.DisplayIndex = originalColumn.DisplayIndex;
                    column.Header = originalColumn.Header;
                    //column.Footer = originalColumn.Footer; !! causes error
  
                    foreach (AggregateFunction func in originalColumn.AggregateFunctions)
                        column.AggregateFunctions.Add(func);
  
                }
            }
0
Vlad
Telerik team
answered on 06 Jun 2011, 04:04 PM
Hello,

 Generally if you have UI element in the footer you cannot copy element simply with this code:
...
column.Footer = originalColumn.Footer;
...

You need to clone this otherwise you will get "Element is already a child of another element" exception. 

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Steve
Top achievements
Rank 1
answered on 07 Jun 2011, 04:04 PM
Cloning removed the error but did not produce the summary.

From your responses its apparent that this has not been done before. At this moment we are considering removing all RadGridViews ands moving to Component One.
Tags
GridView
Asked by
Khurram Ilyas
Top achievements
Rank 1
Answers by
Khurram Ilyas
Top achievements
Rank 1
Vlad
Telerik team
Steve
Top achievements
Rank 1
Share this question
or