How to print grid with Hierarchy Child Template

16 posts, 0 answers
  1. Joe Lozina
    Joe Lozina avatar
    25 posts
    Member since:
    Jun 2010

    Posted 22 Jun 2010 Link to this post

    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
  2. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 22 Jun 2010 Link to this post

    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
  3. DevCraft banner
  4. Joe Lozina
    Joe Lozina avatar
    25 posts
    Member since:
    Jun 2010

    Posted 22 Jun 2010 Link to this post

    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
  5. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 23 Jun 2010 Link to this post

    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
  6. Joe Lozina
    Joe Lozina avatar
    25 posts
    Member since:
    Jun 2010

    Posted 23 Jun 2010 Link to this post

    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
  7. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 24 Jun 2010 Link to this post

    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
  8. Joe Lozina
    Joe Lozina avatar
    25 posts
    Member since:
    Jun 2010

    Posted 24 Jun 2010 Link to this post

    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
  9. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 24 Jun 2010 Link to this post

    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
  10. Joe Lozina
    Joe Lozina avatar
    25 posts
    Member since:
    Jun 2010

    Posted 16 Jul 2010 Link to this post

    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
  11. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 16 Jul 2010 Link to this post

    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
  12. Joe Lozina
    Joe Lozina avatar
    25 posts
    Member since:
    Jun 2010

    Posted 22 Jul 2010 Link to this post

    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
  13. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 22 Jul 2010 Link to this post

    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
  14. Karthik
    Karthik avatar
    5 posts
    Member since:
    Dec 2013

    Posted 09 Dec 2013 Link to this post

    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.
  15. Karthik
    Karthik avatar
    5 posts
    Member since:
    Dec 2013

    Posted 09 Dec 2013 Link to this post

    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 ?
  16. Sureshbabu
    Sureshbabu avatar
    2 posts
    Member since:
    Jan 2016

    Posted 07 Jan in reply to Yavor Georgiev Link to this post

    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);
        }
    }

  17. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    280 posts

    Posted 12 Jan Link to this post

    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
Back to Top
DevCraft banner