public static void PrintPreview(this RadGridView grid, PrintSettings settings)
        {
            var rtb    = CreateRadRichTextBox(grid, settings);
            var window = CreatePreviewWindow(rtb);

            window.ShowDialog();
        }
        private static RadDocument CreateDocument(RadGridView grid, PrintSettings settings)
        {
            RadDocument document = null;

            using (var stream = new MemoryStream())
            {
                EventHandler <GridViewElementExportingEventArgs> elementExporting = (s, e) =>
                {
                    if (e.Element == ExportElement.Table)
                    {
                        e.Attributes["border"] = "0";
                    }
                    else if (e.Element == ExportElement.HeaderRow)
                    {
                        if (settings.HeaderBackground != null)
                        {
                            e.Styles.Add("background-color", settings.HeaderBackground.ToString().Remove(1, 2));
                        }
                    }
                    else if (e.Element == ExportElement.GroupHeaderRow)
                    {
                        if (settings.GroupHeaderBackground != null)
                        {
                            e.Styles.Add("background-color", settings.GroupHeaderBackground.ToString().Remove(1, 2));
                        }
                    }
                    else if (e.Element == ExportElement.Row)
                    {
                        if (settings.RowBackground != null)
                        {
                            e.Styles.Add("background-color", settings.RowBackground.ToString().Remove(1, 2));
                        }
                    }
                };

                grid.ElementExporting += elementExporting;

                grid.Export(stream, new GridViewExportOptions()
                {
                    Format            = Telerik.Windows.Controls.ExportFormat.Html,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters  = grid.ShowGroupFooters
                });

                grid.ElementExporting -= elementExporting;

                stream.Position = 0;

                document = new HtmlFormatProvider().Import(stream);
            }

            return(document);
        }
 private static RadRichTextBox CreateRadRichTextBox(RadGridView grid, PrintSettings settings)
 {
     return(new RadRichTextBox()
     {
         IsReadOnly = true,
         LayoutMode = DocumentLayoutMode.Paged,
         IsSelectionEnabled = false,
         IsSpellCheckingEnabled = false,
         Document = CreateDocument(grid, settings)
     });
 }
        public static void Print(this RadGridView grid, PrintSettings settings)
        {
            var rtb    = CreateRadRichTextBox(grid, settings);
            var window = new RadWindow()
            {
                Height = 0, Width = 0, Opacity = 0, Content = rtb, Owner = WpfHelper.GetActiveWindow()
            };

            rtb.PrintCompleted += (s, e) => { window.Close(); };
            window.Show();

            rtb.Print("MyDocument", Telerik.Windows.Documents.UI.PrintMode.Native);
        }
        private static Workbook CreateWorkBook(RadGridView grid, PrintSettings settings)
        {
            Workbook book = null;

            using (var stream = new MemoryStream())
            {
                grid.Export(stream, new GridViewExportOptions()
                {
                    Format            = Telerik.Windows.Controls.ExportFormat.Csv,
                    ShowColumnFooters = grid.ShowColumnFooters,
                    ShowColumnHeaders = grid.ShowColumnHeaders,
                    ShowGroupFooters  = grid.ShowGroupFooters
                });

                stream.Position = 0;

                book = new CsvFormatProvider().Import(stream);
            }

            return(book);
        }