Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > print preview works, but not print
 

print preview works, but not print

I have following situation (application is in c#):

PrintPreview dialog shows exactly what should be printed, but when someone clicks on print icon of it, it shows error: operation failed: index was out of range. Must be non-negative and less than the size of collection. Parametar name: index.

I am not sure what exactly happens after one clicks print icon, as it is managed by .net, but shouldn't it run exactly the same code that forms the pages and print? But when I do that manually (skip printpreview dialog and use PrintDocument.Print() ) everything works without the problem.

Is there any way to debug this?
ivan.icin  Monday, September 07, 2009 10:09 AM
Hello ivan.icin,

Could you please add a break point at the first line of the print code. You can debug it step by step to see which line cause the problem.

According to your description. I think maybe when you click the print preview, some parameters have been changed, which result in the wrong parameters for real print process. You can test these two situation and watch the parameter.
1. Click print preview, then click print. write download the parameters
2. Directly click print, compare the parameters with them in the step 1.

Please inform me the result.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byivan.icin Friday, September 11, 2009 7:43 AM
  •  
Kira Qian  Wednesday, September 09, 2009 3:04 AM
Hello ivan.icin,

Could you please add a break point at the first line of the print code. You can debug it step by step to see which line cause the problem.

According to your description. I think maybe when you click the print preview, some parameters have been changed, which result in the wrong parameters for real print process. You can test these two situation and watch the parameter.
1. Click print preview, then click print. write download the parameters
2. Directly click print, compare the parameters with them in the step 1.

Please inform me the result.

Sincerely,
Kira Qian
Please mark the replies as answers if they help and unmark if they don't.
  • Marked As Answer byivan.icin Friday, September 11, 2009 7:43 AM
  •  
Kira Qian  Wednesday, September 09, 2009 3:04 AM

You can use google to search for other answers

Custom Search

More Threads

• Databinding 101 question
• gridview boundfields vs autogenerated columns
• Binding a combobox to a View throws exception
• Tabcontrol
• Customizing the sortglyph in the datagridview
• Missing Properties using Object Data Source and Partial Classes
• Problem with Concurrency violations when deleting with cascade delete on
• Rich textbox and Context Menu
• Datagridview not showing row for new record
• How to prevent DataGrid from collapsing on parent row update?