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

Printiing: Spreading grid cols over multiple pages

Thread ID:

Created:

Updated:

Platform:

Replies:

23682 Jan 18,2005 01:42 AM Jan 24,2005 07:38 AM Windows Forms 7
loading
Tags: GridControl
Frank Laus
Asked On January 18, 2005 01:42 AM

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 02:03 AM

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 03:05 AM

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 03:35 AM

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;
	dlg.ShowDialog();
}

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);
	}
	else
	{
		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 04:27 AM

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 05:44 AM

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 07:02 AM

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 07:38 AM

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?

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.

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.

;