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

Print Selection and Pages From..to

I want to print a selected row in grid and from one page to other page. How can I do it ? I saw a sample about printing selection in this forum but it''s not correct. Thank you.

7 Replies

AD Administrator Syncfusion Team November 25, 2004 07:51 AM

Here is a thread that shows how you can print selected ranges. It worked for the 2 users that responded in that thread. If it does not work for you, can you upload a sample that shows the problem? I do not know of an easy way of printing only certain pages except to derive a GridPrintDocument and override OnBeginPrint. In your override, copy up the code from our implementation modified to only include pages with new pageFronm and pageTo properties that you add. We plan on re-working the current print support at some point after this 3.0 release. We will make this easier at that point.

DB David Bosak November 25, 2004 11:35 PM

Thank you, But the example you suggested me worked not correctly, it only hilights the selected cells, not print. I want to print (to printer) a selected row on datagrid and print from page 1 to page 2. Thanks.

AD Administrator Syncfusion Team November 26, 2004 01:52 AM

The suggested code seems to work for me to printpreview in this sample using version for me. This sample does not work for you? To only print the first so many pages, there is a sample way to do this. You handle the PrintPage event and set e.HasMorepages to flase and e.Cancel = true when you wnat to stop. This is also illustrated in the above sample. But if you only want to print an arbitary range of pages, I do not know of a simple way to do this.

DB David Bosak November 26, 2004 02:43 AM

Thank you Clay Burch, But I don''t allow user select cell, they can only select "one" row by clicking the left pane, so your code run not correctly when I select a row. How can I improve it ? Thank you,

DB David Bosak November 26, 2004 03:04 AM

And I really want to "print" (not print preview) from one page to another page with ordinal number of page being type in Print Dialog by user. I don''t know how to get the from page and to Page. Thank you for your help. Your sample code is very good.

AD Administrator Syncfusion Team November 26, 2004 03:44 AM

For the selections problem, you will have to change the range types form row ranges ot cell ranges. Below is button handler code to do this. If you want to PRINT from some page to some page, you can try to use the AllowSomePages member of teh PrintDialog. The PrintPrevievDialog does not have this member. Below is a modififed button handler. I am not sure it works as I currently do not have access to a printer.
private void button2_Click(object sender, System.EventArgs e)
	if (this.gridDataBoundGrid1 != null)
		if(this.gridDataBoundGrid1.Selections.Count == 0)
			MessageBox.Show("Select some cells first.");
		GridRangeInfoList rangeList = new GridRangeInfoList();
		foreach(GridRangeInfo range in this.gridDataBoundGrid1.Selections)
				rangeList.Add(range.ExpandRange(1, 0, this.gridDataBoundGrid1.Model.RowCount, this.gridDataBoundGrid1.Model.ColCount) );
		foreach(GridRangeInfo range in rangeList)
		GridPrintDocument pd = new GridPrintDocument(this.gridDataBoundGrid1, true);
		pd.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.Selection;
		PrintPreviewDialog dlg = new PrintPreviewDialog() ;
		dlg.Document = pd;
 private void button3_Click(object sender, System.EventArgs e)
	if (this.gridDataBoundGrid1 != null)
		GridPrintDocument pd = new GridPrintDocument(this.gridDataBoundGrid1);
		PrintDialog dlg = new PrintDialog() ;
		dlg.Document = pd;
		dlg.AllowSomePages = true;
		if(dlg.ShowDialog() == DialogResult.OK)

DB David Bosak November 26, 2004 09:06 PM

Thank Clay Burch very much.

Live Chat Icon For mobile
Up arrow icon