
Thanks,
-Saqib Ali
16 Answers, 1 is accepted

Thanks,
-Saqib ali
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:
// copy original column aggregate functions here
Vlad
the Telerik team

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

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

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
You've not copied the column headers nor ShowColumnFooters/ShowGroupFooters values from the original grid.
Sincerely yours,Vlad
the Telerik team

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

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

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);
}
}
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.
Vlad
the Telerik team

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.