Print GridView Footer

19 posts, 0 answers
  1. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 15 Jul 2010 Link to this post

    I have a gridview with the data totaled in the footer. When printing the gridview, the totals are not there. Is there a way to print the footer? 

    Thanks,
    Katie
  2. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 16 Jul 2010 Link to this post

    Hi katie,

     If you're using the print code in our example, go to PrintExtensions.cs and find the ToPrintFriendlyGrid method.

    Just before the line 'grid.SelectedItems.Clear();' add the following line: 'grid.ShowColumnFooters = source.ShowColumnFooters;'

    This method is the place to customize the printed grid, so you can set any other properties that you need here.

    All the best,
    Yavor Georgiev
    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 16 Jul 2010 Link to this post

    I am looking at the example, but I do not have the line 'grid.SelectedItems.Clear();'. Possibly it is a different version - at the bottom of the example it says 'RadControls for WPF Q1 2010, released on 09 March 2010.'

    I added the line: 'grid.ShowColumnFooters = source.ShowColumnFooters;' to the ToPrintFriendlyGrid method on the PrintExtensions class. Now it will show the footer, but it is blank. How do I get the totals to appear?

    Thanks,
    Katie
  5. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 16 Jul 2010 Link to this post

    Hi katie,
    if (originalColumn != null)
        {
            column.Width = originalColumn.ActualWidth;
            column.DisplayIndex = originalColumn.DisplayIndex;
        }
    }

    and change it to:

    foreach (var func in originalColumn.AggregateFunctions)
    {
        column.AggregateFunctions.Add(func);
    }
     

    Find this code:

    Sincerely yours,
    Yavor Georgiev
    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
  6. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 16 Jul 2010 Link to this post

    Thanks for the quick reply, but I'm still having problems. I do not have those lines of code to replace. This is my ToPrintFriendlyGrid method:


     

    static GridViewDataControl ToPrintFriendlyGrid(GridViewDataControl source)

     

    {

     

    RadGridView grid = new RadGridView();

     

    grid.ItemsSource = source.ItemsSource;

    grid.RowIndicatorVisibility =

    Visibility.Collapsed;

     

    grid.ShowGroupPanel =

    false;

     

    grid.CanUserFreezeColumns =

    false;

     

    grid.IsFilteringAllowed =

    false;

     

    grid.AutoExpandGroups =

    true;

     

    grid.AutoGenerateColumns =

    false;

     

    grid.ShowColumnFooters = source.ShowColumnFooters;

     

    foreach (GridViewDataColumn column in source.Columns.OfType<GridViewDataColumn>())

     

    {

     

    GridViewDataColumn newColumn = new GridViewDataColumn();

     

    newColumn.Width = column.ActualWidth;

    newColumn.DisplayIndex = column.DisplayIndex;

    newColumn.DataMemberBinding =

    new System.Windows.Data.Binding(column.UniqueName);

     

    grid.Columns.Add(newColumn);

    }

     

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

     

     

    grid.SortDescriptors.AddRange(source.SortDescriptors);

    grid.GroupDescriptors.AddRange(source.GroupDescriptors);

    grid.FilterDescriptors.AddRange(source.FilterDescriptors);

     

    return grid;

     

    }



    I tried adding the suggested code inside the foreach loop, but I only got errors when running.


    Thanks,
    Katie
  7. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 16 Jul 2010 Link to this post

    Hi katie,

     Just before grid.Columns.Add(newColumn) add:

    foreach (var func in column.AggregateFunctions)
    {
        newColumn.AggregateFunctions.Add(func);
    }

    All the best,
    Yavor Georgiev
    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
  8. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 16 Jul 2010 Link to this post

    Again, thanks for the quick reply, but it is still not working. I no longer get the error, but the footer is still blank.

    Thanks,
    Katie
  9. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 19 Jul 2010 Link to this post

    Hi katie,

     Could you please send me as much of the code as possible as .txt attachments to a forum post? You can also send your application to my email address: Yavor.Georgiev AT telerik.com

    All the best,
    Yavor Georgiev
    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
  10. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Jul 2010 Link to this post

    Hi katie,

     I have determined that you need to change the ToPrintFriendlyGrid method like so:

    static GridViewDataControl ToPrintFriendlyGrid(GridViewDataControl source)
    {
        RadGridView grid = new RadGridView();
     
        grid.ItemsSource = source.ItemsSource;
        grid.RowIndicatorVisibility = Visibility.Collapsed;
        grid.ShowGroupPanel = false;
        grid.CanUserFreezeColumns = false;
        grid.IsFilteringAllowed = false;
        grid.AutoExpandGroups = true;
        grid.AutoGenerateColumns = false;
     
        foreach (GridViewDataColumn column in source.Columns.OfType<GridViewDataColumn>())
        {
            GridViewDataColumn newColumn = new GridViewDataColumn();
            newColumn.Width = column.ActualWidth;
            newColumn.DisplayIndex = column.DisplayIndex;
            newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
     
            newColumn.Footer = column.Footer;
     
            foreach (var func in column.AggregateFunctions)
            {
                newColumn.AggregateFunctions.Add(func);
            }
     
            grid.Columns.Add(newColumn);
        }
     
        StyleManager.SetTheme(grid, StyleManager.GetTheme(grid));
     
        grid.ShowColumnFooters = source.ShowColumnFooters;
        grid.SortDescriptors.AddRange(source.SortDescriptors);
        grid.GroupDescriptors.AddRange(source.GroupDescriptors);
        grid.FilterDescriptors.AddRange(source.FilterDescriptors);
     
        return grid;
    }

    Please let me know how it goes for you.

    Greetings,
    Yavor Georgiev
    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
  11. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 21 Jul 2010 Link to this post

    Yavor,

    I am getting an error: "Specified element is already the logical child of another element. Disconnect it first."


    Thanks,
    Katie
  12. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Jul 2010 Link to this post

    Hello katie,

     It seems that on your side the RadGridView has not yet had a chance to calculate the aggregate functions in the printed grid. Try with this code:

    static GridViewDataControl ToPrintFriendlyGrid(GridViewDataControl source)
    {
        RadGridView grid = new RadGridView();
     
        grid.ItemsSource = source.ItemsSource;
        grid.RowIndicatorVisibility = Visibility.Collapsed;
        grid.ShowGroupPanel = false;
        grid.CanUserFreezeColumns = false;
        grid.IsFilteringAllowed = false;
        grid.AutoExpandGroups = true;
        grid.AutoGenerateColumns = false;
     
        foreach (GridViewDataColumn column in source.Columns.OfType<GridViewDataColumn>())
        {
            GridViewDataColumn newColumn = new GridViewDataColumn();
                newColumn.Width = column.ActualWidth;
            newColumn.DisplayIndex = column.DisplayIndex;
            newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
     
            newColumn.Footer = column.Footer;
     
            foreach (var func in column.AggregateFunctions)
            {
                newColumn.AggregateFunctions.Add(func);
            }
     
            grid.Columns.Add(newColumn);
        }
     
        grid.CalculateAggregates();
     
        StyleManager.SetTheme(grid, StyleManager.GetTheme(grid));
     
      
        grid.ShowColumnFooters = source.ShowColumnFooters;
        grid.SortDescriptors.AddRange(source.SortDescriptors);
        grid.GroupDescriptors.AddRange(source.GroupDescriptors);
        grid.FilterDescriptors.AddRange(source.FilterDescriptors);
     
        return grid;
    }

    All the best,
    Yavor Georgiev
    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
  13. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 21 Jul 2010 Link to this post

    Yavor,

    Unfortunately, I am still getting the same error.


    Thanks,
    Katie
  14. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 21 Jul 2010 Link to this post

    Hello katie,

     I'm attaching a sample application. I hope it helps you.

    Sincerely yours,
    Yavor Georgiev
    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
  15. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 22 Jul 2010 Link to this post

    Yavor,

    I am using Visual Studio 2008, so I was unable to open the sample file. The different versions of Visual Studio could be the reason printing footers will not work for me, but will work for you. Do you know of any way to fix this? If you do not think this is the issue, could you re-do the sample in Visual Studio 2008?


    Thanks,
    Katie
  16. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 23 Jul 2010 Link to this post

    Hello katie,

     Please find attached a VS2008 version of the sample project.

    Sincerely yours,
    Yavor Georgiev
    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
  17. Matt Eland
    Matt Eland avatar
    24 posts
    Member since:
    Sep 2009

    Posted 14 Oct 2010 Link to this post

    This forum post was helpful to me since the documentation on aggregates is relatively low compared to your other documentation.

    I was having this exact same issue and found that the call to CalculateAggregates() resolved the issue on everything but the first page.

    I would like to be able to print this stuff, but if it's not working on page 1 then I have issues and can't rely on the footer for printing. This is in VS 2010 using Silverlight 4 and Q2 SP2.

    Is there an extra step that would force things to refresh before the initial render?
  18. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 19 Oct 2010 Link to this post

    Hello Matt Eland,

     Which version of our controls are you using? Could you please open a support ticket and attack your application? Generally, before you add the canvas to the PrintPage, you can add it to a popup, attach this popup to the visual tree and on its Loaded event remove the canvas from the popup. This can 'cheat' the controls into kickstarting their usual lifecycle that does not execute property when printing. However, this approach does not always produce the desired results.

    Sincerely yours,
    Yavor Georgiev
    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
  19. Ben
    Ben avatar
    9 posts
    Member since:
    Aug 2012

    Posted 09 Jun 2011 Link to this post

    Hi Katie,

    Although this reply might be a little late, I have encountered the same error that you were experiencing:
    InvalidOperationException : "Specified element is already the logical child of another element. Disconnect it first."

    This turned out to be occuring because my grid headers were not simple text (they were comprised of TextBlock elements and in some cases even more complex UI components). When the GridViewDataGridopyPropertiesFrom() method copies the header it merely performs a simple copy (i.e. newColumn.Header = oldColumn.Header). Since the TextBlock (or other UIElement will have already been placed within the logical tree in its original scope, when you call Measure on a control containing this copied UIElement it will throw an InvalidOperationException because you cannot change the logical parent of the object).

    The good news is that you can work around this :-). What you will need to do is to detect if the Header (or Footer) is not a simple text property (column.Header is UIElement will work for this purpose), and clone the element rather than just copying it. There are several ways that you could go about cloning it, the code below will work (does for me):

    public static UIElement CloneElement(UIElement originalUIElement)
    {
        UIElement clone = null;
        if (originalUIElement != null)
        {
            string serialisedUIElement = XamlWriter.Save(originalUIElement);
            StringReader stringReader = new StringReader(serialisedUIElement);
            XmlReader xmlReader = XmlTextReader.Create(stringReader, new XmlReaderSettings());
            clone = (UIElement)XamlReader.Load(xmlReader);
        }
        return clone;
    }

    I'm sure there are better ways of doing this, but it works for now.

    Hopefully this post will be useful to someone.

    Regards,
        Mark
  20. katie
    katie avatar
    13 posts
    Member since:
    Sep 2012

    Posted 14 Sep 2012 Link to this post

    Mark,

    I finally got around to trying this solution, but now I am getting a different error. When I try to clone the footer, it says "The tag AggregateResultList does not exist in XML namespace http://schemas.telerik.com/2008/xaml/presentation
    line 1 position 2". The XAML of one of my footers is below. Do you or anyone have any suggestions on what I could try next?

    Thanks,
    Katie


    <Telerik:GridViewDataColumn.Footer>
     <Telerik:AggregateResultsList ItemsSource="{Binding}" VerticalAlignment="Center" Grid.Column="6">
             <ItemsControl.ItemTemplate>
                     <DataTemplate>
                             <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                                     <TextBlock VerticalAlignment="Center" Text="{Binding Caption}" />
                                     <TextBlock VerticalAlignment="Center" Text="{Binding FormattedValue}" />
                                    </StackPanel>
                            </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                    <StackPanel Orientation="Vertical" />
                            </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
            </Telerik:AggregateResultsList>
    </Telerik:GridViewDataColumn.Footer>
Back to Top
UI for WPF is Visual Studio 2017 Ready