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

Grid Printing on multiple pages

Using a very helpful example on the Syncfusion knowledgebase website, I was able to implement the printing of multiple grids on a print preview dialog box. I have two questions. The first is, how can I dynamically tell the print privew dialog to display the page in landscape mode? The second is - How can I get the print dialog to show multiple pages? Is this a problem with the grid or a problem with the dialog. The print preview dialog cuts off the data at the length/width of the page. Thanks in advance.

16 Replies

AD Administrator Syncfusion Team May 19, 2004 11:54 AM UTC

Here is some code for landscape setting.
private void PrintPreview_Click(object sender, System.EventArgs e)
{
	if (gridControl1 != null)
	{
		try 
		{
			GridPrintDocument pd = new GridPrintDocument(gridControl1, true); //Assumes the default printer
			PrintPreviewDialog dlg = new PrintPreviewDialog() ;
			dlg.Document = pd;
		pd.DefaultPageSettings.Landscape = true; //<<<<<<<<<<<<< added
			dlg.ShowDialog();
		} 
		catch(Exception ex) 
		{ 
			MessageBox.Show("An error occurred attempting to preview the file to print - " + ex.Message);
		}
	}
}
If you use the default printing support, it should page OK in printpreview. The only know problem that I know about is if a cell to too big to fit on a single page. Is this what you are running into? Now if you derive the GridPrintDocument, then you would have to make sure you do things properly. For example, if you override OnPrintPage, you control whether the process thinks there is another page to be printed by setting e.HasMorePages.


MD Mark Deraeve October 14, 2004 09:44 AM UTC

Hi, when I use the: pd.DefaultPageSettings.Landscape = true; it still prints my page in portrait... Is there something else I can try? >Here is some code for landscape setting. >
>private void PrintPreview_Click(object sender, System.EventArgs e)
>{
>	if (gridControl1 != null)
>	{
>		try 
>		{
>			GridPrintDocument pd = new GridPrintDocument(gridControl1, true); //Assumes the default printer
>			PrintPreviewDialog dlg = new PrintPreviewDialog() ;
>			dlg.Document = pd;
>		pd.DefaultPageSettings.Landscape = true; //<<<<<<<<<<<<< added
>			dlg.ShowDialog();
>		} 
>		catch(Exception ex) 
>		{ 
>			MessageBox.Show("An error occurred attempting to preview the file to print - " + ex.Message);
>		}
>	}
>}
>
> >If you use the default printing support, it should page OK in printpreview. The only know problem that I know about is if a cell to too big to fit on a single page. Is this what you are running into? > >Now if you derive the GridPrintDocument, then you would have to make sure you do things properly. For example, if you override OnPrintPage, you control whether the process thinks there is another page to be printed by setting e.HasMorePages. >


AD Administrator Syncfusion Team October 14, 2004 10:15 AM UTC

It seems to work OK for me in this sample. Does this sample work for you? Can you post a sample that shows the problem you are having? Landscape_580.zip


MB Madhavi Balusu November 3, 2004 07:09 PM UTC

Hi Clay, I think I am running into this problem: ">If you use the default printing support, it should page OK in printpreview. The only know problem that I know about is if a cell to too big to fit on a single page. Is this what you are running into? " When my grid''s column width''s go beyond a page width, it is not printing the Right hand side columns in the new page!!? This is happening even if I remove the BeginPrint and PrintPage events. SO I don''t think they are the culprits... Ideally I would like to fit all my columns in the same page, else I need the RHS columns to print on a new page... Thanks.


AD Administrator Syncfusion Team November 3, 2004 08:13 PM UTC

This problem mentioned above is if a single column column is wider than the print page. If at least one scrollable column is fully visible, then things should work. Can you see this problem in one of our samples (say any of the grid\samples\CellTypes samples that have a preview button)? If not, can you post a sample showing this problem?


MB Madhavi Balusu November 3, 2004 09:52 PM UTC

This is how far I am right now: Its got something to do with: dlg.Document.DefaultPageSettings.Landscape = true; setting. If I don''t set the above line then things do carry over to the next page. I create a grid in memory for printing and don''t actually display it. Only use for the printing. Almost seems like a SyncFusion bug but I could be wrong.


AD Administrator Syncfusion Team November 3, 2004 11:03 PM UTC

Are you using grid.HScrollPixel = true? If so, in your printiing code, try setting this to false before you print, and then setting it back to true after you print to see if this handles this problem.


AD Administrator Syncfusion Team November 4, 2004 01:41 AM UTC

setting grid.HScrollPixel = false; fixed it. But I never set grid.HScrollPixel = true though! Any idea what was happening? Thanks.


AD Administrator Syncfusion Team November 4, 2004 09:23 AM UTC

I am not sure as the default setting (from an attribute settings) is False. I searched the grid code for ''HScrollPixel ='' and could not find a spot where the library code is explicitly setting it to any specific value.


MB Madhavi Balusu November 5, 2004 03:59 PM UTC

Actually, that did not fix the problem. I think you guys definately have a bug here. When in landscape mode, and the last column is out the bounds by a "buggy" width, the last column is not carrying over to the next page. When I set myGrid.Width = pdGrid.DefaultPageSettings.Bounds.Width * 2; It does print on the 2nd page. Having said that I have another question: In my PrintPage event handler, I am trying to adjust the heights and widths of my grid as I want based on the e.PageBounds.Width. when the pagebound''s width is greater than the grid, I readjust the column widths and do a myGrid.RowHeights.ResizeToFit. This leaves more space at the bottom as the rows now do not wrap due to increased width. What is happening the grid is NOT automatically figuring out I have more height left at the bottom since the width increased and displaying more rows at the bottom during printing. How do I print more/less rows as the available height to display the grid changes?


AD Administrator Syncfusion Team November 5, 2004 04:44 PM UTC

We will be looking into the printing to actually fix this problem along with another RTL printing issue we have. But the work will not be done until after we get the 3.0 release out. You might also try setting VScrollPixel = false to see if that has an effect on the height problem. If you can tell me how to see the problem in one of our samples where teh work-around does not work, maybe I can suggest something else.


AD Administrator Syncfusion Team November 5, 2004 05:25 PM UTC

Do you have a sample that readjusts grid''s row''s height and width during printing (onPrintPage)? I can''t find one..


AD Administrator Syncfusion Team November 5, 2004 06:05 PM UTC

You can probably use QueryColWidth to manage this. Here is a forum link to a thread with a sample that hides columns by setting their colwidth = 0 using this event. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=10972


AD Administrator Syncfusion Team November 5, 2004 06:58 PM UTC

Here is a sample that shows the more rows not printing on the 2nd, 3rd page althoug there is space at the bottom of those pages.. maskedit_917.zip


AD Administrator Syncfusion Team November 5, 2004 07:35 PM UTC

Clay, I do need the solution for how to make the extra rows at the bottom print when you change the size of a row during printing.. Thanks for your help, Madhavi.


AD Administrator Syncfusion Team November 6, 2004 07:34 PM UTC

Here is the problem. The grid uses GridPrintDocument.OnBeginPrint to determine all the different page''s start rows. And there are no event hooks into the process to allow you to dynamically change the print rectangle as this process takes place. This is why you are seeing this behavior. Missing events that would allow you to handle this problem. We do intend to rework th epronting to expose such events, but it will be after 3.0 is out. Below is your sample back modified to almost do what you need. The only problem I see is that the very first page is the small header row shorter height that the following pages. What it does is to not freeze any rows, and allow the two special headers rows that you added to go off the page as you go from page 1 to page 2. Then for page 2 and on, it displays the original row 0 header to serve as the header you wanted to display. It does this by overriding OnQueryRowHeight to hide and show the original row header. To get OnQueryRowHeight to be hit, in the form the printGrid.Parent needed to be set as well. forumprint_8346.zip

Loader.
Live Chat Icon For mobile
Up arrow icon