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. Image for the cookie policy date

columns wrapping and sizing on printing

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.


3 Replies

SV Srinivasan Vasu Syncfusion Team 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



IS issam 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 :)


SV Srinivasan Vasu Syncfusion Team 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 
 


Loader.
Up arrow icon