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

How to print grid with Hierarchy Child Template

15 Answers 285 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joe Lozina
Top achievements
Rank 1
Joe Lozina asked on 22 Jun 2010, 09:01 AM
Hi,

I would like to print a grid which has a Hierarchy Child Template like the example like the example http://demos.telerik.com/silverlight/#GridView/Hierarchy/HierarchyChildTemplate.

When I try to print the grid only the parent rows are printed and none of the child rows are there.

Regards,
Joe

15 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 22 Jun 2010, 09:29 AM
Hello Joe Lozina,

 If you look at the code-behind for our Printing example in Silverlight, you'll notice that we create a print-friendly clone of the RadGridView that we feed to a PrintDocument. You only need to customize this RadGridView clone in code-behind to include a hierarchy child like the one in your actual RadGridView.

Kind regards,
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
Joe Lozina
Top achievements
Rank 1
answered on 23 Jun 2010, 03:29 AM
Hi Yavor,

Ive seen in the Print method where a print-friendly clone of a RadGridView is created, every column is copied from the original grid into the print grid.

What I'm not sure how or where you would add the Child Grid then add then add the Child grid columns into it.

Can you provide me an example of how to include a hierarchy child grid?

Regards,
Joe
0
Yavor Georgiev
Telerik team
answered on 23 Jun 2010, 09:26 AM
Hello Joe Lozina,

 You can do something like this:

RadGridView actualGrid;
RadGridView printGrid;
 
foreach (var item in actualGrid.ChildTableDefinitions)
{
   printGrid.ChildTableDefinitions.add(item);
}
 
printGrid.HierarchyChildTemplate = actualGrid.HierarchyChildTemplate;

However, you might want to define a separate hierarchy child template that is more print-friendly, with collapsed row indicators, group panel, etc. Assuming you've defined it in your UserControl's Resources with x:key="printHierarchyChildTemplate" :
printGrid.HierarchyChildTemplate = (DataTemplate)this.Resources["printHierarchyChildTemplate"];

Please let me know if you need further assistance.

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
Joe Lozina
Top achievements
Rank 1
answered on 24 Jun 2010, 03:34 AM
Hi Yavor

The  printGrid.ChildTableDefinitions.add(item); line cause the following compile error:

'Telerik.Windows.Data.TableDefinitionCollection' does not contain a definition for 'add' and no extension method 'add' accepting a first argument of type 'Telerik.Windows.Data.TableDefinitionCollection' could be found (are you missing a using directive or an assembly reference?)

Regards,
Joe
0
Vlad
Telerik team
answered on 24 Jun 2010, 07:07 AM
Hi Joe,

 Can you try Add() instead add()?

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
Joe Lozina
Top achievements
Rank 1
answered on 24 Jun 2010, 08:13 AM
Hi Vlad,

That fixed the compile error.

When I print it doesnt display the child grid. My print method is below.

        private void PrintButton_Click(object sender, RoutedEventArgs e)  
        {  
            offsetY = 0d;  
            totalHeight = 0d;  
 
            grid = new RadGridView();  
            grid.Width = 1550;  
            grid.FontSize = 8;  
            grid.DataContext = maintenanceGrid.DataContext;  
            grid.ItemsSource = maintenanceGrid.ItemsSource;  
            grid.RowIndicatorVisibility = Visibility.Collapsed;  
            grid.ShowGroupPanel = false;  
            grid.CanUserFreezeColumns = false;  
            grid.IsFilteringAllowed = false;  
            grid.AutoExpandGroups = true;  
            grid.AutoGenerateColumns = false;  
 
            foreach (GridViewColumn column in maintenanceGrid.Columns.OfType<GridViewColumn>())  
            {  
                GridViewColumn newColumn = (GridViewColumn)Activator.CreateInstance(column.GetType());  
                newColumn.CopyPropertiesFrom(column);  
                grid.Columns.Add(newColumn);  
            }  
 
            foreach (var item in maintenanceGrid.ChildTableDefinitions)  
            {  
                grid.ChildTableDefinitions.Add(item);  
               
            }  
 
            grid.HierarchyChildTemplate = maintenanceGrid.HierarchyChildTemplate;  
 
            StyleManager.SetTheme(grid, StyleManager.GetTheme(maintenanceGrid));  
 
            grid.SortDescriptors.AddRange(maintenanceGrid.SortDescriptors);  
            grid.GroupDescriptors.AddRange(maintenanceGrid.GroupDescriptors);  
            grid.FilterDescriptors.AddRange(maintenanceGrid.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("RadGridView print");  
        }  
 


Do I have to add the GridViewColumns for the Child grid? And how and where would I do it?

Regards,
Joe
0
Yavor Georgiev
Telerik team
answered on 24 Jun 2010, 09:19 AM
Hello Joe Lozina,

 You need to expand your hierarchy items, because by default it is collapsed and won't show up when printing:

foreach (var item in maintenanceGrid.ChildTableDefinitions) 
    grid.ChildTableDefinitions.Add(item); 
                
  
grid.HierarchyChildTemplate = maintenanceGrid.HierarchyChildTemplate;
 
grid.ExpandAllHierarchyItems();

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
Joe Lozina
Top achievements
Rank 1
answered on 16 Jul 2010, 06:03 AM
Hi Yavor,

How do I expand only the child rows that have child grids when printing? So I collapse all the child grids that don't have any data.

When I use grid.ExpandAllHierarchyItems() it expands all the child grids, even if there is no data for the child grid.

You can see this in the third row of attached jpg.

Another question is when printing a grid with child rows is there a way to suppress the Expandable icon for all the rows for the parent grid?

Finally is there a way to disable the selected row color(orange) in a datagrid. So that none of the rows are orange. When you have child grids all the first rows are highlighted orange and it appears when printed.

Regards,
Joe
0
Yavor Georgiev
Telerik team
answered on 16 Jul 2010, 12:11 PM
Hello Joe Lozina,

 To only expand rows that have a hierarchy child, replace the ExpandAllHierarchyItems() line with:

foreach (MyDataClass item in grid.Items)
{
    if (item.MyCollectionProperty.Count > 0)
    {
        grid.ExpandHierarchyItem(item);
    }
}


Regarding row selection, set the IsSynchronizedWithCurrentItem property on all printed grids to false.

Unfortunately, there is no easy way to remove the expandable icon without editing the ControlTemplate of GridViewRow.

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
Joe Lozina
Top achievements
Rank 1
answered on 22 Jul 2010, 06:50 AM
Hi Yavor,

When I print the grid which contains a child grid. if I hide certain columns in both the parent grid and child grid so i can fit it to a A4 page size, the hiding of columns for the parent grid works fine but the hiding of columns for the child grid doesn't work no matter what I do. Is this because the child grid is in a data Template? How can I hide and show child grid columns when printing?

Regards,
Joe
0
Yavor Georgiev
Telerik team
answered on 22 Jul 2010, 08:15 AM
Hello Joe Lozina,

 Could you please open a support ticket and attach your project so that I can see how you perform the hiding?

Best wishes,
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
Karthik
Top achievements
Rank 1
answered on 09 Dec 2013, 11:25 AM
I have implemented same code to print RadGridView and Child data printing. But child RadGridview data not printed. only Parend RadGridView detailas and Child RadGridView Header informations are printed. Kindly suggest me how to print child RadGridview datails along with header. Please find attachment.
0
Karthik
Top achievements
Rank 1
answered on 09 Dec 2013, 11:32 AM
I have to change child grid font size when i expand grid.ExpandHierarchyItem.
foreach (MyDataClass item in grid.Items)
{
    if (item.MyCollectionProperty.Count > 0)
    {
        grid.ExpandHierarchyItem(item);
    }
}
Kindly suggest me how to set child RadGridView font size while printing ?
0
Sureshbabu
Top achievements
Rank 1
answered on 07 Jan 2016, 09:36 PM

Hi Yavor Georgiev,

 I did follow the same code which you have mentioned below. But I am still not able to see the child elements in the Print or PrintPriview. I have replaced MyDataClass with my class name and the MyCollectionProperty to my Property collection. I have used the PrintAndExportExtensions class which is given by Telerik. When I debug the code it is able to go through the collection if any sub elements exists. Please let me know do I have to change any more properties?

 foreach (MyDataClass item in grid.Items)

{
    if (item.MyCollectionProperty.Count > 0)
    {
        grid.ExpandHierarchyItem(item);
    }
}

0
Stefan Nenchev
Telerik team
answered on 12 Jan 2016, 04:01 PM
Hello Sureshbabu,

As advised in the other forum thread - Print Preview Grid Hierarchy - the approach discussed in the current thread is not available anymore. Please, refer to the other thread for more information.

Regards,
Stefan Nenchev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Joe Lozina
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Joe Lozina
Top achievements
Rank 1
Vlad
Telerik team
Karthik
Top achievements
Rank 1
Sureshbabu
Top achievements
Rank 1
Stefan Nenchev
Telerik team
Share this question
or