ResizeToFit rows on printing

Hi,

Is it possible to ResizeToFit rows when PrintingMode = true?

I can set fixed size on QueryRowHeight event but can't find how to do ResizeToFit.

Thanks


7 Replies 1 reply marked as answer

DD Dhivyabharathi Dakshinamurthy Syncfusion Team April 4, 2024 04:12 PM UTC

Hi Dinis Ferreira,

Your requirement is to ResizeToFit the rows when the PrintingMode is set to true in the GridControl. We have prepared a simple sample demonstrating how to achieve this by using both the ResizeToFit and PrintingMode properties of the GridControl.


Below are the code snippets:

 
 
//Sets the ResizeToFit for rows 1 to 5.

  this.gridControl1.Model.RowHeights.ResizeToFit(GridRangeInfo.Rows(1, 5), GridResizeToFitOptions.NoShrinkSize);

  //Sets the ResizeToFit for Column 4.

  this.gridControl1.Model.ColWidths.ResizeToFit(GridRangeInfo.Col(4), GridResizeToFitOptions.NoShrinkSize);        



  private void Print_Click(object sender, EventArgs e)

  {

      gridControl1.PrintingMode = true;

      //Convert the Grid as printing document

      GridPrintDocument gridPrintDocument = new GridPrintDocument(this.gridControl1);

      PrintDialog pd = new PrintDialog();

      pd.Document = gridPrintDocument;

 

      //Print the contents of the Grid

      gridPrintDocument.Print();

  }



We have also attached a sample for your reference. Please review it and let us know if it meets your requirements. If there are any misunderstandings or additional concerns, please feel free to share them with us.


Attachment: GridControl_Print_7e8cb641.zip

Marked as answer

DF Dinis Ferreira April 8, 2024 02:51 PM UTC

Hi,

I haven't explained my situation correctly.

I have a grid with data and later I click a button to print. While adjusting several parameters of grid and page it call grid_QueryRowHeight. Here, if grid.PrintingMode == true I have to adjust rowheights because after reduce columns width some rows may have more than one line.

How can I ResizeToFit the rows, only to printmode, after columns adjustment?

Thanks.




DD Dhivyabharathi Dakshinamurthy Syncfusion Team April 9, 2024 03:52 PM UTC

Hi Dinis Ferreira,

Based on the information provided, it seems that you want to apply the ResizeToFit functionality only in printing mode.


Using ResizeToFit in the QueryRowHeight event may not be the recommended approach to achieve this behavior. Instead, you can set ResizeToFit to all cells in the button click event before calling the Print() method. This approach ensures that ResizeToFit is applied only in printing mode, as per your requirement.

We have modified the sample and attached output screenshot for your reference.

Kindly refer the following code snippets.


  private void Print_Click(object sender, EventArgs e)

  {

      gridControl1.PrintingMode = true;

      GridPrintDocument gridPrintDocument = new GridPrintDocument(this.gridControl1);

      PrintDialog pd = new PrintDialog();

      pd.Document = gridPrintDocument;

 

      if (gridControl1.PrintingMode)

          gridControl1.Model.RowHeights.ResizeToFit(GridRangeInfo.Table());

 

      gridPrintDocument.Print();           

  }


Grid image before exporting


After exporting to pdf



We hope this helps to achieve your requirement. Please let us know, if need any further assistance.



Attachment: GridControl_ResizeToFit_812952d5.zip


DF Dinis Ferreira April 10, 2024 12:05 PM UTC

Hi,

Thanks for  helping.


Your code resize the "main" grid and not resize the "print" grid.

I don't know if its related but to print I use  GridPrintDocumentAdv  and to export to pdf use  GridPDFConverter.


After setting gridControl1.PrintingMode = true; the changes should not apply to "main" grid and only to "print" grid?


Thank you



DD Dhivyabharathi Dakshinamurthy Syncfusion Team April 11, 2024 12:17 PM UTC

Hi Dinis Ferreira,

Based on the output image provided in the previous update, ResizeToFit is applied only to the PrintGrid, not to the MainGrid.

When printing, if the condition for printingMode being true is satisfied, we apply RowHeights.ResizeToFit, which affects only the printing grid.

We have also ensured this behavior with the GridPrintDocumentAdv, and it works as expected.


If this does not meet your requirement, could you please provide a video reference or image reference with the issue replicated. This will help us better understand the problem and proceed to provide a better solution.



DF Dinis Ferreira April 16, 2024 07:22 AM UTC

Hi,

Thank you for helping but didn't work so I've decide to go another way.




DD Dhivyabharathi Dakshinamurthy Syncfusion Team April 17, 2024 03:43 PM UTC

Hi Dinis Ferreira,


As mentioned earlier, ResizeToFit works properly on our end when PrintingMode is set to true. We have also attached a simple sample in the previous update for your reference. Please review the sample provided. If the issue persists after implementing this workaround, could you please provide a sample where the issue reproduces? Alternatively, you can try replicating the issue in the sample we provided. If possible, providing a video or image reference with the issue replicated would be helpful.


Providing these details will help us better understand the issue and work towards finding a solution promptly.



Loader.
Up arrow icon