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
close icon

PrintDialog.ToPage

Using the GridControl, how can I set the ToPage property of the PrintDialog ? (pd is a PrintDocument) This give me 0 _print_dialog.PrinterSettings = pd.PrinterSettings This give me 9999 _print_dialog.PrinterSettings.ToPage = pd.PrinterSettings.MaximumPage This give me 0 _print_dialog.PrinterSettings.ToPage = pd.PrinterSettings.ToPage

12 Replies

AD Administrator Syncfusion Team March 6, 2006 12:00 PM UTC

Hi Stephane, Sorry for the delay in replying. By default, the ToPage property will be zero for GridPrintDocument. You can follow the code snippet to set the property. GridPrintDocument pd = new GridPrintDocument(gridDataBoundGrid1); pd.PrinterSettings.FromPage = 1; pd.PrinterSettings.ToPage = 2; PrintDialog ptdlg = new PrintDialog(); ptdlg.Document = pd; ptdlg.AllowSelection = true; ptdlg.AllowSomePages = true; ptdlg.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.SomePages; //ptdlg.PrinterSettings.FromPage = 3; //ptdlg.PrinterSettings.ToPage = 4; ptdlg.ShowDialog(); Also refer to MSDN Library ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDrawingPrintingPrinterSettingsClassToPageTopic.asp ) for more details on ToPage property. Let us know if this helps Best Regards, Madhan.


AD Administrator Syncfusion Team March 6, 2006 02:59 PM UTC

Thank for the answer. I think I did not express what I needed correctly. Is there a way to get the number of pages to print and set it in the "to" field of the PrintDialog. ex: When I do a print preview, it will indicate that the grid is 10 pages long. When opening the PrintDialog, I want to see 10. Thank


AD Administrator Syncfusion Team March 6, 2006 04:48 PM UTC

I tried this but it''s not accurate and it''s not direct. Dim w, h, fw, fh, pages As Integer w = pd.DefaultPageSettings.Bounds.Width h = pd.DefaultPageSettings.Bounds.Height fw = active_window.Grid.Model.ColWidths.GetTotal(0, active_window.Grid.Model.ColCount) fh = active_window.Grid.Model.RowHeights.GetTotal(0, active_window.Grid.Model.RowCount) ''System.Windows.Forms.MessageBox.Show(w & ":" & h & "**" & fw & ":" & fh) pages = CInt((fw / w) + 0.5) * CInt((fh / h) + 0.5)


AD Administrator Syncfusion Team March 10, 2006 12:38 PM UTC

Hi Stephane, Sorry for the delayed response, GridPrintDocument calculates the page details and draws the contents dynamically in the OnBeginPrint/OnPrintPage overrides. So, it is possible to get the page no only after showing the PrintPreviewDialog. Here is a demo sample. Let us know if you need any further information. Best regards, Madhan.


AD Administrator Syncfusion Team March 10, 2006 04:06 PM UTC

Do you know a way to call the OnBeginPrint without calling the print preview before ?


AD Administrator Syncfusion Team March 14, 2006 03:41 AM UTC

Hi Stephane, The OnBeginPrint only be triggered while Printing or during preview. We are currently working on a sample to calculate pages in a indirect way, which we will update you soon. Best regards, Madhan.


AD Administrator Syncfusion Team March 16, 2006 03:55 PM UTC

Thank


AD Administrator Syncfusion Team April 4, 2006 07:41 PM UTC

Any update ?


AD Administrator Syncfusion Team April 5, 2006 10:55 AM UTC

Hi Stephane, Sorry for the delayed response. It seems tricky; I will update you the sample this week end. Thanks for the patience. Best regards, Madhan


AD Administrator Syncfusion Team April 7, 2006 10:01 AM UTC

Hi Stephane, Thanks for being patient. The easiest and fastest approach to calculate the number of pages is by calling the PrintPreviewDialog and cancelling it in the BeginPrint event of the PrintDocument. The performance is good, even the number of pages is large. Sample : Print Issue For more details on Printing : Printing in .Net with C# Best regards, Madhan


AD Administrator Syncfusion Team April 7, 2006 07:19 PM UTC

Thank !


AD Administrator Syncfusion Team August 28, 2006 12:40 AM UTC

I have a better way of doing this. Instead of opening a PrintPreviewDialog, just call PrintDocument.Print(). Still hook to begin print event and cancel straight away as in the sample provided.

// Print code

GridPrintDocument pd = new GridPrintDocument(gridDataBoundGrid1);
pd.BeginPrint += new System.Drawing.Printing.PrintEventHandler(pd_BeginPrint);

pd.Print();

PrintDialog ptdlg = new PrintDialog(); ptdlg.Document = pd; ptdlg.PrinterSettings.PrintRange = System.Drawing.Printing.PrintRange.SomePages; ptdlg.AllowSomePages = true;
ptdlg.ShowDialog();

// End Print Code

// Begin Print Event Handler

private void pd_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
e.Cancel = true;
}

// End Begin Print Event Handler

Loader.
Live Chat Icon For mobile
Up arrow icon