18 Answers, 1 is accepted
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.
Yavor Georgiev
the Telerik team

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
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

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
Just before grid.Columns.Add(newColumn) add:
foreach (var func in column.AggregateFunctions)
{
newColumn.AggregateFunctions.Add(func);
}
Yavor Georgiev
the Telerik team

Thanks,
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
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;
}
Greetings,
Yavor Georgiev
the Telerik team

I am getting an error: "Specified element is already the logical child of another element. Disconnect it first."
Thanks,
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;
}
Yavor Georgiev
the Telerik team

Unfortunately, I am still getting the same error.
Thanks,
Katie
I'm attaching a sample application. I hope it helps you.
Sincerely yours,Yavor Georgiev
the Telerik team

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
Please find attached a VS2008 version of the sample project.
Sincerely yours,Yavor Georgiev
the Telerik team

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?
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

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

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>