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

Conversion of the content from a RadGridView in a RadDocument

2 Answers 11 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vincent
Top achievements
Rank 1
Vincent asked on 22 Aug 2018, 01:07 PM
Hi,

i have o problem whit the conversion of the content of a RadGridView in a RadDocument.

Inside of the RadGridView i have 5 columns with different width.
But the columns inside the RadDocument have all  the same width.

My source code worked correctly whith the Telerik-Controls version 2014.3.1202.45.
The columns inside the RadDocument inherit the widths from the columns inside the RadGridView.

But after the update to the version 2018.1.220.45 it does not work correctly anymore.
The columns inside the RadDocument have all the same width.

Please, can you help me to find a solution?


Best Regards,
Vincent Dinculescu


Here my source code:

XAML of  the RadGrisView:

    . . . . . .
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn x:Name="vg_letztaend" Header="Datum"
Width="120"
DataMemberBinding="{Binding VgLetztaend}"
IsReadOnly="True"
                                                        TabStopMode="Skip"
IsFilterable="False"
IsSortable="True" />
                    <telerik:GridViewDataColumn x:Name="vg_betreff" Header="Betreff"
 Width="270"
DataMemberBinding="{Binding VgBetreff}"
IsReadOnly="True"  
                                                        TabStopMode="Stop"
IsFilterable="False"
IsSortable="True"
TextWrapping="Wrap" />
                    <telerik:GridViewDataColumn x:Name="vg_text" Header="Text"
Width="300"
DataMemberBinding="{Binding VgText}"
IsReadOnly="True"  
                                                        TabStopMode="Stop"  
TextWrapping="Wrap"  
IsFilterable="False"
IsSortable="True" />
                    <telerik:GridViewDataColumn x:Name="bearbeiterName" Header="Bearbeiter"
Width="140"
DataMemberBinding="{Binding BearbeiterName}"
IsReadOnly="True"
                                                        TabStopMode="Skip"
IsFilterable="False"
IsSortable="True" />
                    <telerik:GridViewDataColumn x:Name="vg_bearbeiter" Header="Kennung"
Width="80"
DataMemberBinding="{Binding VgBearbeiter}"
IsReadOnly="True"
                                                        TabStopMode="Skip"
 IsFilterable="False"
IsSortable="True" />
                </telerik:RadGridView.Columns>
    . . . . . .


Source code for the conversion from a RadGridView in a RadDocument:

        public static void PrintPreview(this RadGridView grid)
        {
            Window owner = grid.GetVisualParent<Window>();
            var rtb = CreateRadRichTextBox(grid);
            PrintCommand = new DelegateCommand<object[]>(PrintData, CanExecutePrintCommand);
            ExitCommand = new DelegateCommand<object>(Exit, CanExecuteExitCommand);
            var window = CreatePreviewWindow(rtb, owner, settings);
            window.ShowDialog();
        }

        private static RadRichTextBox CreateRadRichTextBox(RadGridView grid)
        {
            return new RadRichTextBox
            {
                IsReadOnly = true,
                LayoutMode = DocumentLayoutMode.Paged,
                IsSelectionEnabled = false,
                IsSpellCheckingEnabled = false,
                Document = CreateDocument(grid),
                Padding = new Thickness(15, 10, 10, 10),
                DocumentInheritsDefaultStyleSettings = true,
                FontFamily = new FontFamily("Arial"),
                FontSize = 12,
            };
        }

        private static RadDocument CreateDocument(RadGridView grid)
        {
            RadDocument document;

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


                stream.Position = 0;

                HtmlFormatProvider provider = new HtmlFormatProvider();
                provider.ImportSettings = new HtmlImportSettings();
                provider.ImportSettings.UseDefaultStylesheetForFontProperties = false;

                document = provider.Import(stream);
                document.SectionDefaultPageMargin = new Telerik.Windows.Documents.Layout.Padding(30);
                document.SectionDefaultPageOrientation = PageOrientation.Landscape;

            }

            return document;
        }





2 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 24 Aug 2018, 02:47 PM
Hello Vincent,

Thank you for the provided code snippets.

In order to keep the widths of the columns when exporting the RadGridView to RadDocument in the current version, you can utilize the ElementExporting event of the RadGridView. You can set the Width of the VisualParameters property of the GridViewElementExportingEventArgs to be equal to the width of the column for all of the cells and header cells. I am attaching a sample project demonstrating this approach for your reference. 

I hope you find this helpful.

Regards,
Vladimir Stoyanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Vincent
Top achievements
Rank 1
answered on 05 Sep 2018, 06:07 AM
Hello Vladimir,

Thank you for the explanations and for the sample project.
The sample project was very useful.

I have implemented this solution and it works perfectly.

Thank you very much!

Best Regards,
Vincent
Tags
GridView
Asked by
Vincent
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Vincent
Top achievements
Rank 1
Share this question
or