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 12:51 PM UTC

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? http://64.78.18.34/Support/Forums/message.aspx?MessageID=10972 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 26, 2004 04:35 AM UTC

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 06:52 AM UTC

The suggested code seems to work for me to printpreview in this sample using version 2.1.0.9 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 07:43 AM UTC

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 08:04 AM UTC

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 08:44 AM UTC

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)
{
	//selected
	if (this.gridDataBoundGrid1 != null)
	{
		if(this.gridDataBoundGrid1.Selections.Count == 0)
		{
			MessageBox.Show("Select some cells first.");
			return;
		}
		GridRangeInfoList rangeList = new GridRangeInfoList();
		foreach(GridRangeInfo range in this.gridDataBoundGrid1.Selections)
		{
			if(!range.IsCells)
				rangeList.Add(range.ExpandRange(1, 0, this.gridDataBoundGrid1.Model.RowCount, this.gridDataBoundGrid1.Model.ColCount) );
			else
				rangeList.Add((GridRangeInfo)range.Clone());
		}
		this.gridDataBoundGrid1.Selections.Clear(false);
		foreach(GridRangeInfo range in rangeList)
			this.gridDataBoundGrid1.Selections.Add(range);
		GridPrintDocument pd = new GridPrintDocument(this.gridDataBoundGrid1, true);
		pd.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.Selection;
		PrintPreviewDialog dlg = new PrintPreviewDialog() ;
		dlg.Document = pd;
		dlg.ShowDialog();
	}
}
 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)
		{
			pd.Print();
		}
	}
}


DB David Bosak November 27, 2004 02:06 AM UTC

Thank Clay Burch very much.

Loader.
Live Chat Icon For mobile
Up arrow icon