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

[Solved] Printing too slow on relatively larger data sets

4 Answers 216 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Vassili King
Top achievements
Rank 1
Vassili King asked on 12 Jan 2011, 12:06 AM
Hello,

I've implemented printing on my grid in a way very similar to one described here: http://www.telerik.com/community/forums/silverlight/gridview/print-grid-in-color.aspx.

My grid's columns are built in code. When it is populated with data, I have 20 groups and about 1000 records in all of them combined. Exporting works fine, but printing takes forewer. Printing works better on smaller data sets. Is there a way to speed up the printing?

Essentially, there are three methods involved in the print event: btnPrint_Click, FormatGrid (where I generate a grid, called _grid, based on the one displayed, caleld rgvMainGrid), and doc_PrintPage.  Here is the code:


        double offsetY;
        double totalHeight;
        Canvas canvas;
        RadGridView _grid;

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                PrintDocument doc = new PrintDocument();

                FormatGrid("print");
                canvas = new Canvas();
                if (_grid.Items.Groups.Count > 0)
                {
                    for (int i = 0; i < _grid.Items.Groups.Count; i++ )
                    {
                        this._grid.ExpandGroup(this._grid.Items.Groups[i] as IGroup); //expanding the groups before printing the list
                    }
                }
                canvas.Children.Add(_grid);

                doc.PrintPage += this.doc_PrintPage;
                doc.Print("Test Print");
            }
            catch (Exception ex)
            {
                TrackException(ex, "method: btnPrint_Click");
            }
        }

        void FormatGrid(string action)
        {
            try
            {
                offsetY = 0d;
                totalHeight = 0d;

                int counter = 0;

                _grid = new RadGridView();
                _grid.DataContext = rgvMainGrid.DataContext;
                _grid.ItemsSource = rgvMainGrid.ItemsSource;
                _grid.RowIndicatorVisibility = Visibility.Collapsed;
                _grid.ShowGroupPanel = false;
                _grid.CanUserFreezeColumns = false;
                _grid.IsFilteringAllowed = false;
                _grid.AutoExpandGroups = true;
                _grid.AutoGenerateColumns = false;

                foreach (GridViewColumn column in rgvMainGrid.Columns.OfType<GridViewColumn>())
                {
                    if(counter > 1) //Need to exclude first two columns
                    {
                        GridViewColumn newColumn = (GridViewColumn)Activator.CreateInstance(column.GetType());
                        newColumn.CopyPropertiesFrom(column);
                        _grid.Columns.Add(newColumn);
                    }
                    counter++;
                }

                StyleManager.SetTheme(_grid, StyleManager.GetTheme(rgvMainGrid));

                _grid.SortDescriptors.AddRange(rgvMainGrid.SortDescriptors);
                _grid.GroupDescriptors.AddRange(rgvMainGrid.GroupDescriptors);
                _grid.FilterDescriptors.AddRange(rgvMainGrid.FilterDescriptors);

                ScrollViewer.SetHorizontalScrollBarVisibility(_grid, ScrollBarVisibility.Hidden);
                ScrollViewer.SetVerticalScrollBarVisibility(_grid, ScrollBarVisibility.Hidden);

                if (!string.IsNullOrEmpty(action) && action.ToLower() != "export_to_excel")
                {
                    _grid.ElementExporting += new EventHandler<GridViewElementExportingEventArgs>(rgvMainGrid_ElementExporting);
                    _grid.ElementExported += new EventHandler<GridViewElementExportedEventArgs>(rgvMainGrid_ElementExported);
                }
            }
            catch (Exception ex)
            {
                TrackException(ex, "method: FormatGrid(string action)");
            }
        }

       void doc_PrintPage(object sender, PrintPageEventArgs e)
        {
            try
            {
               
                e.PageVisual = canvas;

                if (totalHeight == 0)
                {
                    totalHeight = _grid.DesiredSize.Height;
                }

                Canvas.SetTop(_grid, -offsetY);

                //PrintableArea
                offsetY += e.PrintableArea.Height;
                e.HasMorePages = offsetY <= totalHeight;
            }
            catch (Exception ex)
            {
                TrackException(ex, "method: doc_PrintPage");
            }
        }

Any help would be greatly appreciated!

Thank you!
-VK.

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Jan 2011, 08:32 AM
Hi,

 Since the Silverlight 4 printing will work with plain bitmaps and the grid needs to create all rows in order to provide UI for this image better approach will be to use Telerik Reporting

Best wishes,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Vassili King
Top achievements
Rank 1
answered on 12 Jan 2011, 05:20 PM
Hi Vlad,

The grid is only a very small part of a large web application. I don't see how Telerik Reports could be benefitial, unless there is a sleek way to utilize Reports in my app without a major rewrite. Is there a good demo with code-behind for printing in the Reports?

Thanks!
-VK.
0
Vlad
Telerik team
answered on 13 Jan 2011, 07:57 AM
Hello,

 Have you checked the link I've posted?

Regards,
Vlad
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Vassili King
Top achievements
Rank 1
answered on 13 Jan 2011, 05:20 PM
Vlad,

I sure did. The site contains a demo and links to some video tutorials (on which, btw, navigational controls do not allow you to change the position on a timeline) on how to create Telerik Reports projects. I could not locate anything on printing an existing RadGridView. I also could not find any code-behind similar to Telerik's Silverlight controls demo. Frankly, this sounds almost like a sales pitch than a functional advise from you. :) My license, though, includes Telerik Reports from what I can remember. I just can't spend any time rewriting parts of my application utilizing a new technology at this point.

-VK.
Tags
GridView
Asked by
Vassili King
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Vassili King
Top achievements
Rank 1
Share this question
or