We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

columns wrapping and sizing on printing

Thread ID:

Created:

Updated:

Platform:

Replies:

123781 Apr 20,2016 11:33 PM UTC Apr 26,2016 06:04 PM UTC WPF 3
loading
Tags: SfDataGrid
issam
Asked On April 20, 2016 11:33 PM UTC

Hi,

is there a way to make the columns auto fitting their content while printing ?

or at least setting the width/height at runtime .

please look  at the attached image




even in landscape mode the printed grid cannot fit the page

- the 3rd column (adress) can have 1 or 2 lines, but it's not printed correctly .
- the 3 last columns have some extra space but we can't use for other columns .

an help is welcome .

thanks and good day.


Srinivasan Vasu [Syncfusion]
Replied On April 21, 2016 05:51 PM UTC

Hi Issam,

Thanks for contacting Syncfusion support.

Query 1 [Set Height in Runtime]:

We have analyzed your query and you can achieve your requirement by overriding GetRowHeight in GridPrintManager as like in the below code example. Within this method you can get the row height based on content using DataGrid.ColumnSizer.GetAutoRowHeight method.

Please refer the below code example:


C#

public class CustomPrintManager : GridPrintManager

    {

        SfDataGrid dataGrid;

        GridRowSizingOptions gridRowSizingOptions = new GridRowSizingOptions();

        double Height = double.NaN;

        public CustomPrintManager(SfDataGrid grid)

            : base(grid)

        {

            dataGrid = grid;

        }


        protected override double GetRowHeight(object record, int rowindex)

        {

            if (record != null)

            {

                var actualrowindex = GridIndexResolver.ResolveToRowIndex(this.dataGrid, rowindex);

                if (this.dataGrid.GridColumnSizer.GetAutoRowHeight(actualrowindex, gridRowSizingOptions, out Height))

                {

                    return Height;

                }

            }

            return base.GetRowHeight(record, rowindex);

        }


    }

  public partial class MainWindow : Window

    {

        GridRowSizingOptions gridRowSizingOptions = new GridRowSizingOptions();

        double Height = double.NaN;


        public MainWindow()

        {

            InitializeComponent();

            this.syncgrid.Loaded += syncgrid_Loaded;           

        }

        void syncgrid_Loaded(object sender, RoutedEventArgs e)

        {

            syncgrid.PrintSettings.PrintManagerBase = new CustomPrintManager(this.syncgrid);

        }

     

        private void Button_Click(object sender, RoutedEventArgs e)

        {

            syncgrid.PrintSettings.AllowPrintByDrawing = false;

            syncgrid.ShowPrintPreview();

            syncgrid.PrintSettings.AllowColumnWidthFitToPrintPage = true;           

        }


        private void Button_Click_1(object sender, RoutedEventArgs e)

        {

            syncgrid.Print();           

        }


    }



Query 2[Printed grid cannot fit in the page]:

We prepared the custom sample as per your scenario and we regret to inform you that we are unable reproduce the  reported “Printed grid cannot fit in the page” issue in our end. In Landscape mode,  SfDataGridGrid has been printed correctly. Please refer the sample in below mentioned location and please share the modified sample as per your application along with replication procedure to replicate the issue. This would be more helpful for us to serve you better.

Sample Link: http://www.syncfusion.com/downloads/support/forum/123781/ze/Printing-1744439065



Regards,
Srinivasan


issam
Replied On April 25, 2016 12:14 PM UTC

again, all my issues was resolved :) thanks a lot,


just one last this please :
- how to set the columns vertical alignement while printing ?, i tried to make it in the column definition but it had no effect on printing

really appreciate :)

Srinivasan Vasu [Syncfusion]
Replied On April 26, 2016 06:04 PM UTC

Hi Issam, 
 
We have analyzed your query. You can achieve your requirement by using override GetColumnElement in PrintManagerBase. In this method, you can set VerticalAlignment for each cell based on mapping name. 
 
Please refer the below code example: 
 
C# 
  protected override object GetColumnElement(object record, string mappingName) 
        { 
            var element = base.GetColumnElement(record, mappingName); 
            if (mappingName == "OrderID") 
                (element as FrameworkElement).VerticalAlignment = VerticalAlignment.Top; 
            return element; 
        }      
 
Please find the sample from the below location. 
 
 
 
Regards, 
Srinivasan 
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;