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 : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Print Grids

Thread ID:

Created:

Updated:

Platform:

Replies:

69407 Oct 26,2007 10:12 AM UTC Nov 19,2007 10:18 AM UTC WinForms 11
loading
Tags: GridControl
mattia locatelli
Asked On October 26, 2007 10:12 AM UTC

Hello,
I have a variable number of grids to print one after the other on the same PrintDocument.
When the fist grid finished printing there should be some withe space and then the second grid should print.

For achieve this result I calculate the space occupied by the first grid on the current page and add it to the PageSettings.Margins.Top for the current page.
When I printPreview the document I get the first page of the second grid printed over the first grid and the next pages of the second grid printed correctly at the right position. Why doesn't the first page take into count the new margins i changed?

mattia locatelli
Replied On October 29, 2007 08:18 AM UTC

Hi, I just want to know why if I set the margins on the PrintPageEventArgs.PageSettings.Margins and call the base.OnPrintPage of the GridPrintDocumentClass they are only applied from the second page of the document printed.


>Hello,
I have a variable number of grids to print one after the other on the same PrintDocument.
When the fist grid finished printing there should be some withe space and then the second grid should print.

For achieve this result I calculate the space occupied by the first grid on the current page and add it to the PageSettings.Margins.Top for the current page.
When I printPreview the document I get the first page of the second grid printed over the first grid and the next pages of the second grid printed correctly at the right position. Why doesn't the first page take into count the new margins i changed?

Jeba S [Syncfusion]
Replied On November 1, 2007 05:12 AM UTC

Hi Me,

You can print two or more grids in a same page by deriving the GridPrintDocument and overriding its OnPrintPage method. In the override, don't call the base class.

Please refer the code snippets:

protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev)
{
//don not call baseclass...
//set where you want the grid displayed...
int width = grid1.Model.ColWidths.GetTotal(0, grid1.Model.ColCount);
int height = grid1.Model.RowHeights.GetTotal(0, grid1.Model.RowCount);
Rectangle topGridRect = new Rectangle(ev.MarginBounds.Left, ev.MarginBounds.Top, width, height);
grid1.DrawGrid(ev.Graphics, topGridRect, false);
ev.Graphics.DrawRectangle(Pens.Black, topGridRect);

//set where you want the second grid displayed...
width = grid2.Model.ColWidths.GetTotal(0, grid2.Model.ColCount);
height = grid2.Model.RowHeights.GetTotal(0, grid2.Model.RowCount);
Rectangle botGridRect = new Rectangle(ev.MarginBounds.Left, ev.PageBounds.Height/2, width, height);
grid2.DrawGrid(ev.Graphics, botGridRect, false);
ev.Graphics.DrawRectangle(Pens.Black, botGridRect);
}


Please refer the sample which implements the above said feature
http://websamples.syncfusion.com/samples/Grid.Windows/F69407/main.htm

Kindly let us know if you need any further assistance.

Thank you for using Syncfusion Products.

Best Regards,
Jeba.



mattia locatelli
Replied On November 2, 2007 01:35 PM UTC

Hi,
I've seen the code from the example but what I want to do is a little bit different.
What i want to do is to print diffent grids into the same print document. Let's say I have two grids Grid1 and Grid2. Grid1 occupies a page and a half, Grid2 occupies two pages. I want to print all Grid1, that occupies a page and half, and then in the same page start printing Grid2 CALLING THE BASE.PRINT() METHOD of the grids.
I've already figured out how to print the grids one after the other, the problems is that when I print Grid2 the print start a the top of the page even if I change the Margin.Top proprieties of the printPageEventArgs.

>Hi Me,

You can print two or more grids in a same page by deriving the GridPrintDocument and overriding its OnPrintPage method. In the override, don't call the base class.

Please refer the code snippets:

protected override void OnPrintPage(System.Drawing.Printing.PrintPageEventArgs ev)
{
//don not call baseclass...
//set where you want the grid displayed...
int width = grid1.Model.ColWidths.GetTotal(0, grid1.Model.ColCount);
int height = grid1.Model.RowHeights.GetTotal(0, grid1.Model.RowCount);
Rectangle topGridRect = new Rectangle(ev.MarginBounds.Left, ev.MarginBounds.Top, width, height);
grid1.DrawGrid(ev.Graphics, topGridRect, false);
ev.Graphics.DrawRectangle(Pens.Black, topGridRect);

//set where you want the second grid displayed...
width = grid2.Model.ColWidths.GetTotal(0, grid2.Model.ColCount);
height = grid2.Model.RowHeights.GetTotal(0, grid2.Model.RowCount);
Rectangle botGridRect = new Rectangle(ev.MarginBounds.Left, ev.PageBounds.Height/2, width, height);
grid2.DrawGrid(ev.Graphics, botGridRect, false);
ev.Graphics.DrawRectangle(Pens.Black, botGridRect);
}


Please refer the sample which implements the above said feature
http://websamples.syncfusion.com/samples/Grid.Windows/F69407/main.htm

Kindly let us know if you need any further assistance.

Thank you for using Syncfusion Products.

Best Regards,
Jeba.




Jeba S [Syncfusion]
Replied On November 5, 2007 10:45 AM UTC

Hi Me,

Thank you for your update.

I would strongly encourage you to prepare a small sample just to show the issue, so that we could debug it here. That would help us quicker identify the problem. Or you can modify the sample in the previous reply to show this problem, we can probably suggest some way to avoid it.

Best Regards,
Jeba.



mattia locatelli
Replied On November 5, 2007 11:33 AM UTC

This example define a sample grid and a GridPrintDocument.
In this example I can see just the first and the last page of the grid ( I suppose it is beacuse I set DeafaultMarginTop to 200 and PageSettingsMargin.Top to 400 ).

Thanks for your help.

>Hi Me,

Thank you for your update.

I would strongly encourage you to prepare a small sample just to show the issue, so that we could debug it here. That would help us quicker identify the problem. Or you can modify the sample in the previous reply to show this problem, we can probably suggest some way to avoid it.

Best Regards,
Jeba.





TestGridPosition.zip

mattia locatelli
Replied On November 8, 2007 10:38 AM UTC

Any news on this?



Jeba S [Syncfusion]
Replied On November 8, 2007 12:33 PM UTC

Hi Me,

Sorry for the delay in response.

Instead of trying to adjust the page margins in OnPrintPage, please try to adjust the margins in the rinterSettings.DefaultPageSetting before calling the dlg.ShowDialog.


GridPrintDocument pd = new GridPrintDocument(this.gridDataBoundGrid1);
pd.PrinterSettings.DefaultPageSettings.Margins.Top =xxx;


Kindly let us know if this helps.

Best Regards,
Jeba.


mattia locatelli
Replied On November 12, 2007 02:42 PM UTC

No,
It doesn't help. I just wanted to set the margin.Top of the first page of the grid at 400 and the margin.Top of others pages at 100 and print the grid.
But when I do this, as you can see in the example, the second page of the grid in the print preview occupies only half of the page and not the entire space available for printing. And also if I do the opposite (Margin.Top of the first page = 100 and of the others page = 400 when I do the print preview I only saw the first and the last page.




TestGridPosition.zip

mattia locatelli
Replied On November 13, 2007 01:05 PM UTC

Hi,
i found a workaround for this by changing the code in the GridPrintDocument. But I have a question and I need to show you the code. Can I upload the GridPrintDocument source code here?


Jeba S [Syncfusion]
Replied On November 15, 2007 11:48 AM UTC

Hi Me,

Sorry for the delay in response.

We would prefer if you upload the modified source by creating a new Incident with Title "Print Grids -F69407". Or else you can post the modifed code snippets with your question in this thread itself. We will anlayse and update you.

Best Regards,
Jeba.




mattia locatelli
Replied On November 19, 2007 10:18 AM UTC

Hi Jeba,
Iève created the incident. Thanks for your help and your patience.



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

;