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

Printiing: Spreading grid cols over multiple pages

Thread ID:





23682 Jan 18,2005 06:42 AM UTC Jan 24,2005 12:38 PM UTC WinForms 7
Tags: GridControl
Frank Laus
Asked On January 18, 2005 06:42 AM UTC

Hi, when printing grids which are wider than the page the grid control splits the grid and prints the the columns on different pages (e.g. the first two cols on the first and the remaining 3 cols on the second page). How can I determine which cols are printed on the current page, e.g. to change the header or footer accordingly? Thanks Frank

Administrator [Syncfusion]
Replied On January 18, 2005 07:03 AM UTC

Check the grid.PrintInfo object and its m_awPageFirstCol member, though there may also be other properties in the PrintInfo object useful to you. PrintInfo in populated in the document.OnBeginPrint method so it should be populate in the PrintPage event.

Frank Laus
Replied On January 18, 2005 08:05 AM UTC

I still don''t understand the values of the PrintInfo collections. I have 8 pages to print and when the last page is being printed m_awPageFirstCol.Count is 3 and m_awPageFirstRow.Count is 5. The grid is broken horizontally into two pages. So what do the values and sizes of/in these collections mean?

Administrator [Syncfusion]
Replied On January 18, 2005 08:35 AM UTC

Here is code that shows how to access these arrays.
private void button1_Click(object sender, System.EventArgs e)
	GridPrintDocument pd = new GridPrintDocument(this.gridControl1, true);
	PrintPreviewDialog dlg = new PrintPreviewDialog();
	dlg.Document = pd;

	pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
	pageNo = 0;

int pageNo = 0;
private void pd_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
	int nPageRowIndex = 0;
	int nPageColIndex = 0;

	if (this.gridControl1.Properties.PageOrder == 0)
		nPageRowIndex = pageNo/(gridControl1.PrintInfo.m_awPageFirstCol.Count-1);
		nPageColIndex = pageNo%(gridControl1.PrintInfo.m_awPageFirstCol.Count-1);
		nPageRowIndex = pageNo%(gridControl1.PrintInfo.m_awPageFirstRow.Count-1);
		nPageColIndex = pageNo/(gridControl1.PrintInfo.m_awPageFirstRow.Count-1);

	int leftCol = (int)this.gridControl1.PrintInfo.m_awPageFirstCol[nPageColIndex];
	int topRow = (int)this.gridControl1.PrintInfo.m_awPageFirstRow[nPageRowIndex];

	Console.WriteLine("page:{0}  leftcol:{1}  toprow:{2}", pageNo, leftCol, topRow);
	pageNo += 1;

Frank Laus
Replied On January 18, 2005 09:27 AM UTC

Thank you for the snippet. I just noticed another problem: When using the preview function (with a simple single page example grid of 20 rows) the preview is shown correctly. But when I use the print function in the preview dialog (i.e. I don''t call Print() myself) page is 1 and toprow is 21!? What can I do to have a reset within the preview dialog before printing a previewed grid from this dialog?

Administrator [Syncfusion]
Replied On January 18, 2005 10:44 AM UTC

There may be a simpler way to get at this, but one thing you can do is to subscribe to the MouseDown event of the toolbar on the PrintPreviewDialog, and in the handler reset the page count. To subscribe to the event, you can pick out the toolbar from the dialog''s COntrols collection. foreach(Control c in dlg.Controls) { if(c is ToolBar) ((ToolBar)c).MouseDown += new MouseEventHandler(Form1_MouseDown); } dlg.ShowDialog(); private void Form1_MouseDown(object sender, MouseEventArgs e) { this.pageNo = 0; }

Frank Laus
Replied On January 24, 2005 12:02 PM UTC

Hi, is it correct that the number of pages the grid is printed on horizontally is m_awPageFirstCol.Count-1? Or is there another way to get the number of pages a grid which is too wide for a single pages is broken into? Thanks Frank

Administrator [Syncfusion]
Replied On January 24, 2005 12:38 PM UTC

I think so. Using m_awPageFirstCol.Count is the way to get the number of pages that will be printed due to too many columns to fit. Is this not working for you?


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon