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

How to create Telerik report runtime using RadGridView

2 Answers 80 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yogesh
Top achievements
Rank 1
Yogesh asked on 25 Apr 2014, 01:12 PM
Currently I am using print and print preview code from "Print and Export with RadDocument" WPF Demo.
this is not working if more than 250 records in grid and Print and Preview takes too much time.

2 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 25 Apr 2014, 07:39 PM
Hello Yogesh,

I've tried to reproduce the problem you report, but to no avail. You can check the attached sample project for a reference. However, keep in mind that printing approach is not designed for big amounts of data as the RadDocument is saved in the memory in order to be printed.

For advanced printing scenarios I would suggest you to check the Telerik Reporting product. 


Regards,
Yoan
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Yogesh
Top achievements
Rank 1
answered on 28 Apr 2014, 01:01 PM
Thanks Yoan,

I am glad to inform you that I am creating the code for create telerik report runtime using RadGridView :).

Print Code:
public static void PrintTelerikReport(RadGridView p_RadGridView)
        {
            try
            {
                ReportSource _ReportSource = GenerateReport(p_RadGridView);
                ReportProcessor _ReportProcessor = new ReportProcessor();
                _ReportProcessor.PrintReport(_ReportSource, null);
            }
            catch (Exception _Exception)
            {
                MessageBox.Show(_Exception.ToString());
            }
        }


Print Preview Code :
void PrintPreviewTelerikReportViewer_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                rvCommonReportViewer.ReportSource = GenerateReport(_CurrentRadGridView);
                rvCommonReportViewer.RefreshReport();
            }
            catch (Exception _Exception)
            {
                MessageBox.Show(_Exception.ToString());
            }
        }


Common static Method :
private static Telerik.Reporting.Report GenerateReport(RadGridView p_RadGridView)
        {
            #region Variables For Report

            Telerik.Reporting.Report _testReport = new Telerik.Reporting.Report();

            Telerik.Reporting.GroupHeaderSection _GroupHeaderSection = new Telerik.Reporting.GroupHeaderSection();
            Telerik.Reporting.GroupFooterSection _GroupFooterSection = new Telerik.Reporting.GroupFooterSection();
            Telerik.Reporting.PageFooterSection _PageFooterSection = new Telerik.Reporting.PageFooterSection();
            Telerik.Reporting.TextBox _CurrentTimeTextBox = new Telerik.Reporting.TextBox();
            Telerik.Reporting.TextBox _PageInfoTextBox = new Telerik.Reporting.TextBox();
            Telerik.Reporting.ReportHeaderSection _ReportHeaderSection = new Telerik.Reporting.ReportHeaderSection();
            Telerik.Reporting.TextBox _TitleTextBox = new Telerik.Reporting.TextBox();
            Telerik.Reporting.DetailSection _DetailSection = new Telerik.Reporting.DetailSection();

            Telerik.Reporting.Group _Group = new Telerik.Reporting.Group();

            Telerik.Reporting.Drawing.StyleRule _StyleRule1 = new Telerik.Reporting.Drawing.StyleRule();
            Telerik.Reporting.Drawing.StyleRule _StyleRule2 = new Telerik.Reporting.Drawing.StyleRule();
            Telerik.Reporting.Drawing.StyleRule _StyleRule3 = new Telerik.Reporting.Drawing.StyleRule();
            Telerik.Reporting.Drawing.StyleRule _StyleRule4 = new Telerik.Reporting.Drawing.StyleRule();

            double _location = 0.02;
            #endregion

            #region This is for Detail
            foreach (Telerik.Windows.Controls.GridViewColumn _GridViewColumn in p_RadGridView.Columns)
            {
                if (_GridViewColumn.GetType() != typeof(GridViewSelectColumn))
                {
                    double _DataWidth = Convert.ToDouble(_GridViewColumn.Width.Value / 100);

                    Telerik.Reporting.TextBox _tbHeader = new Telerik.Reporting.TextBox();
                    _tbHeader.CanGrow = true;
                    _tbHeader.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(_location), Telerik.Reporting.Drawing.Unit.Inch(0.02083333395421505D));
                    _tbHeader.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(_DataWidth), Telerik.Reporting.Drawing.Unit.Inch(0.40000000596046448D));
                    _tbHeader.Style.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(160)))), ((int)(((byte)(218)))));
                    _tbHeader.Style.Font.Bold = true;
                    _tbHeader.Style.Font.Name = "Segoe UI";
                    _tbHeader.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(8D);
                    _tbHeader.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Center;
                    _tbHeader.StyleName = "Caption";
                    _tbHeader.Value = _GridViewColumn.Header.ToString();

                    _GroupHeaderSection.Items.Add(_tbHeader);



                    Telerik.Reporting.TextBox _tbData = new Telerik.Reporting.TextBox();
                    _tbData.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(_location), Telerik.Reporting.Drawing.Unit.Inch(3.9577484130859375E-05D));
                    _tbData.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(_DataWidth), Telerik.Reporting.Drawing.Unit.Inch(0.20));
                    _tbData.Style.Font.Name = "Segoe UI";
                    _tbData.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(8D);
                    _tbData.Value = "=Fields." + _GridViewColumn.UniqueName.SafeTrim();

                    _DetailSection.Items.Add(_tbData);

                    _location += Convert.ToDouble(_GridViewColumn.Width.Value / 100);
                }
            }
            #endregion

            #region This is for Page Footer
            // labelsGroupFooterSection
            _GroupFooterSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.099999904632568359D);
            _GroupFooterSection.Name = "labelsGroupFooterSection";
            _GroupFooterSection.Style.Visible = false;

            // pageFooter
            _PageFooterSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.44166669249534607D);
            _PageFooterSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {_CurrentTimeTextBox, _PageInfoTextBox});
            _PageFooterSection.Name = "pageFooter";

            // currentTimeTextBox
            _CurrentTimeTextBox.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.02083333395421505D), Telerik.Reporting.Drawing.Unit.Inch(0.02083333395421505D));
            _CurrentTimeTextBox.Name = "currentTimeTextBox";
            _CurrentTimeTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(3.1979167461395264D), Telerik.Reporting.Drawing.Unit.Inch(0.40000000596046448D));
            _CurrentTimeTextBox.Style.Font.Name = "Segoe UI";
            _CurrentTimeTextBox.StyleName = "PageInfo";
            _CurrentTimeTextBox.Value = "=NOW()";

            // pageInfoTextBox
            _PageInfoTextBox.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(3.2395832538604736D), Telerik.Reporting.Drawing.Unit.Inch(0.02083333395421505D));
            _PageInfoTextBox.Name = "pageInfoTextBox";
            _PageInfoTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(3.1979167461395264D), Telerik.Reporting.Drawing.Unit.Inch(0.40000000596046448D));
            _PageInfoTextBox.Style.Font.Name = "Segoe UI";
            _PageInfoTextBox.Style.TextAlign = Telerik.Reporting.Drawing.HorizontalAlign.Right;
            _PageInfoTextBox.StyleName = "PageInfo";
            _PageInfoTextBox.Value = "=PageNumber";
            #endregion
            
            #region This is for Page Header
            // labelsGroupHeaderSection
            _GroupHeaderSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.44166669249534607D);
            _GroupHeaderSection.Name = "labelsGroupHeaderSection";
            _GroupHeaderSection.PrintOnEveryPage = true;

            // reportHeader
            _ReportHeaderSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.35833343863487244D);
            _ReportHeaderSection.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {
            _TitleTextBox});
            _ReportHeaderSection.Name = "reportHeader";

            // titleTextBox
            _TitleTextBox.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Inch(0.20000000298023224D), Telerik.Reporting.Drawing.Unit.Inch(0D));
            _TitleTextBox.Name = "titleTextBox";
            _TitleTextBox.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Inch(6.2375001907348633D), Telerik.Reporting.Drawing.Unit.Inch(0.31999999284744263D));
            _TitleTextBox.Style.Color = System.Drawing.Color.Black;
            _TitleTextBox.Style.Font.Name = "Segoe UI";
            _TitleTextBox.StyleName = "Title";
            _TitleTextBox.Value = "Test Summary Report";
            #endregion
            
            // detail
            _DetailSection.Height = Telerik.Reporting.Drawing.Unit.Inch(0.20);
            _DetailSection.Name = "detail";
             
            _Group.GroupFooter = _GroupFooterSection;
            _Group.GroupHeader = _GroupHeaderSection;

            _testReport.Groups.AddRange(new Telerik.Reporting.Group[] {_Group});
            _testReport.Items.AddRange(new Telerik.Reporting.ReportItemBase[] {_GroupHeaderSection, _GroupFooterSection, _PageFooterSection, _ReportHeaderSection, _DetailSection});

            #region This is for Style
            _testReport.PageSettings.Margins = new Telerik.Reporting.Drawing.MarginsU(Telerik.Reporting.Drawing.Unit.Inch(1D), Telerik.Reporting.Drawing.Unit.Inch(1D), Telerik.Reporting.Drawing.Unit.Inch(1D), Telerik.Reporting.Drawing.Unit.Inch(1D));
            _testReport.PageSettings.PaperKind = System.Drawing.Printing.PaperKind.Letter;
            _testReport.Style.BackgroundColor = System.Drawing.Color.White;
            _testReport.Style.BorderColor.Bottom = System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(160)))), ((int)(((byte)(218)))));
            _testReport.Style.BorderColor.Default = System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(160)))), ((int)(((byte)(218)))));
            _testReport.Style.BorderColor.Left = System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(160)))), ((int)(((byte)(218)))));
            _testReport.Style.BorderColor.Right = System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(160)))), ((int)(((byte)(218)))));
            _testReport.Style.BorderColor.Top = System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(160)))), ((int)(((byte)(218)))));
            _testReport.Style.BorderStyle.Bottom = Telerik.Reporting.Drawing.BorderType.Solid;
            _testReport.Style.BorderStyle.Left = Telerik.Reporting.Drawing.BorderType.Solid;
            _testReport.Style.BorderStyle.Right = Telerik.Reporting.Drawing.BorderType.Solid;
            _testReport.Style.BorderStyle.Top = Telerik.Reporting.Drawing.BorderType.Solid;
            _testReport.Style.LineColor = System.Drawing.Color.FromArgb(((int)(((byte)(37)))), ((int)(((byte)(160)))), ((int)(((byte)(218)))));
            _StyleRule1.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("Title")});
            _StyleRule1.Style.Color = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(58)))), ((int)(((byte)(112)))));
            _StyleRule1.Style.Font.Name = "Tahoma";
            _StyleRule1.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(18D);
            _StyleRule2.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("Caption")});
            _StyleRule2.Style.BackgroundColor = System.Drawing.Color.FromArgb(((int)(((byte)(28)))), ((int)(((byte)(58)))), ((int)(((byte)(112)))));
            _StyleRule2.Style.Color = System.Drawing.Color.White;
            _StyleRule2.Style.Font.Name = "Tahoma";
            _StyleRule2.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(10D);
            _StyleRule2.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
            _StyleRule3.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("Data")});
            _StyleRule3.Style.Color = System.Drawing.Color.Black;
            _StyleRule3.Style.Font.Name = "Tahoma";
            _StyleRule3.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(9D);
            _StyleRule3.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
            _StyleRule4.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
            new Telerik.Reporting.Drawing.StyleSelector("PageInfo")});
            _StyleRule4.Style.Color = System.Drawing.Color.Black;
            _StyleRule4.Style.Font.Name = "Tahoma";
            _StyleRule4.Style.Font.Size = Telerik.Reporting.Drawing.Unit.Point(8D);
            _StyleRule4.Style.VerticalAlign = Telerik.Reporting.Drawing.VerticalAlign.Middle;
            _testReport.StyleSheet.AddRange(new Telerik.Reporting.Drawing.StyleRule[] {
            _StyleRule1,
            _StyleRule2,
            _StyleRule3,
            _StyleRule4});
            _testReport.Width = Telerik.Reporting.Drawing.Unit.Inch(6.4375D);
            #endregion

            _testReport.DataSource = p_RadGridView.ItemsSource;

            return _testReport;
        }


Thank You,
Yogesh Goswami
Tags
GridView
Asked by
Yogesh
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Yogesh
Top achievements
Rank 1
Share this question
or