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

Print GridView Footer

18 Answers 154 Views
GridView
This is a migrated thread and some comments may be shown as answers.
katie
Top achievements
Rank 1
katie asked on 15 Jul 2010, 03:53 PM
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

18 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 16 Jul 2010, 10:02 AM
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
0
katie
Top achievements
Rank 1
answered on 16 Jul 2010, 03:13 PM
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
0
Yavor Georgiev
Telerik team
answered on 16 Jul 2010, 03:27 PM
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
0
katie
Top achievements
Rank 1
answered on 16 Jul 2010, 03:50 PM
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
0
Yavor Georgiev
Telerik team
answered on 16 Jul 2010, 03:57 PM
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
0
katie
Top achievements
Rank 1
answered on 16 Jul 2010, 04:24 PM
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
0
Yavor Georgiev
Telerik team
answered on 19 Jul 2010, 01:34 PM
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
0
Yavor Georgiev
Telerik team
answered on 21 Jul 2010, 12:16 PM
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
0
katie
Top achievements
Rank 1
answered on 21 Jul 2010, 02:26 PM
Yavor,

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


Thanks,
Katie
0
Yavor Georgiev
Telerik team
answered on 21 Jul 2010, 03:57 PM
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
0
katie
Top achievements
Rank 1
answered on 21 Jul 2010, 05:37 PM
Yavor,

Unfortunately, I am still getting the same error.


Thanks,
Katie
0
Yavor Georgiev
Telerik team
answered on 21 Jul 2010, 08:28 PM
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
0
katie
Top achievements
Rank 1
answered on 22 Jul 2010, 08:42 PM
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
0
Yavor Georgiev
Telerik team
answered on 23 Jul 2010, 09:10 AM
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
0
Matt
Top achievements
Rank 2
answered on 14 Oct 2010, 08:35 PM
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?
0
Yavor Georgiev
Telerik team
answered on 19 Oct 2010, 01:55 PM
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
0
Ben
Top achievements
Rank 1
answered on 09 Jun 2011, 05:50 AM
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
0
katie
Top achievements
Rank 1
answered on 14 Sep 2012, 01:43 PM
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>
Tags
GridView
Asked by
katie
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
katie
Top achievements
Rank 1
Matt
Top achievements
Rank 2
Ben
Top achievements
Rank 1
Share this question
or