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.


Thread ID:





41524 Mar 3,2006 11:16 AM Aug 27,2006 08:40 PM Windows Forms 12
Tags: GridControl
Administrator [Syncfusion]
Asked On March 3, 2006 11:16 AM

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

Administrator [Syncfusion]
Replied On March 6, 2006 07:00 AM

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.

Administrator [Syncfusion]
Replied On March 6, 2006 09:59 AM

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

Administrator [Syncfusion]
Replied On March 6, 2006 11:48 AM

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)

Administrator [Syncfusion]
Replied On March 10, 2006 07:38 AM

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.

Administrator [Syncfusion]
Replied On March 10, 2006 11:06 AM

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

Administrator [Syncfusion]
Replied On March 13, 2006 10:41 PM

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.

Administrator [Syncfusion]
Replied On March 16, 2006 10:55 AM


Administrator [Syncfusion]
Replied On April 4, 2006 03:41 PM

Any update ?

Administrator [Syncfusion]
Replied On April 5, 2006 06:55 AM

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

Administrator [Syncfusion]
Replied On April 7, 2006 06:01 AM

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

Administrator [Syncfusion]
Replied On April 7, 2006 03:19 PM

Thank !

Administrator [Syncfusion]
Replied On August 27, 2006 08:40 PM

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);


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

// 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


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.