|
Hey, just wanted to say thank you, was exactly what I was after.
Plugged it in and hey presto working in a few minutes, very much appreciated buddy.
|
|
|
|
|
Hay Great Work.
Here a sample for HideColumns
printer.HideColumns.Add("Firma");
printer.HideColumns.Add("Anrede")
modified 23-Jul-13 2:25am.
|
|
|
|
|
Here's an alternative:
var print = new DGVPrinter;
print.HideColumns.Add(RequestList.Columns[1].Name);
Steve G
|
|
|
|
|
Hi Steve,
I make a fair bit of use of the "page break on value change" feature. Would it be useful and/or difficult to provide some sort of functionality whereby I could specify a change of subtitle (or title etc.) when a page break occurs? Perhaps a special formatting placeholder in the subtitle/title string which would be used if BreakOnValueChange is specified?
e.g. dgvp.subtitle = "Group ID: {&BreakVal}"
where DGVPrinter substitutes the relevant value for {&BreakVal} if BreakOnValueChange is specified or blank if not.
Thanks
Derek
modified 10-Jul-13 5:10am.
|
|
|
|
|
That's a very interesting suggestion - I'm going to have to think about how I could do this ...
Steve G.
|
|
|
|
|
Hi Steve,
I'm a huge fan of your work, this turns out to be exactly what I needed. Just letting you know that I would also find this to be an excellent feature if possible. Definitely not necessary, but it sure would be a nice added bonus to the already amazing class you've put together! Thanks again
-Curtis F.
|
|
|
|
|
A very easy to use Data Grid Viewer!
|
|
|
|
|
Hello. I've been using your DGV Printer Helper for a while and it is really great. Now I have a requirement which I cant seem to find the solution to. What I need is to print the footer only on the last page. I saw another comment by a user who had the same requirement and you said that you would send him a beta version with that functionality added. Will it be possible for you to send be that beta version too or possibly tell me how to do that with the current version?
|
|
|
|
|
Yes, no problem. Email me and I can send you the beta.
Steve G.
|
|
|
|
|
Hi Steve,
just upgraded to version 4.3. All fine except with one piece of my code where I am using EmbeddedPrint() to write 3 DGVs to a page. It all worked fine in the previous version but I'm now getting an ArgumentOutOfRange Exception on the final (3rd) call to EmbeddedPrint(). This is a VB project and I am using the compiled dll. I reaslise I could rewrite to use the new improved embedded print process, but I don't understand why the upgrade has 'broken' this particular print routine. Any ideas? Here's the log trace:
.ctor ,********************* New Trace *********************
EmbeddedPrint,EmbeddedPrint process started
SetupPrint ,SetupPrint process started
SetupPrint ,Initial Printer Margins are 1, 0, 129, 0
SetupPrint ,PrintRange is AllPages
SetupPrintRange,Grid Printout Range is 3 columns
SetupPrintRange,Grid Printout Range is 16 rows
measureprintarea,PageSet 0 Information ----------------------------------------------
measureprintarea,Measured columns 0,1,2
measureprintarea,Original Column Widths: 273,48,56
measureprintarea,Overridden Column Widths: -1,-1,-1
measureprintarea,Final Column Widths: 273,48,56
measureprintarea,pageset print width is 379, total column width to be printed is 377
PrintPage ,Print Page processing page 3 -----------------------
PrintPage ,Print Page printing page 3 part 1
PrintPage ,Current Margins are 1, 0, 129, 0
PrintPage ,Print Page printed rows 0 to 15
PrintPage ,Print Page printed columns 0,1,2
EmbeddedPrint,EmbeddedPrint process started
SetupPrint ,SetupPrint process started
SetupPrint ,Initial Printer Margins are 0, 0, 461, 0
SetupPrint ,PrintRange is AllPages
SetupPrintRange,Grid Printout Range is 6 columns
SetupPrintRange,Grid Printout Range is 3 rows
measureprintarea,PageSet 0 Information ----------------------------------------------
measureprintarea,Measured columns 0,1,2,3,4,5
measureprintarea,Original Column Widths: 40,41,189,38,35,37
measureprintarea,Overridden Column Widths: -1,-1,-1,-1,-1,-1
measureprintarea,Final Column Widths: 40,41,189,38,35,37
measureprintarea,pageset print width is 381, total column width to be printed is 380
PrintPage ,Print Page processing page 2 -----------------------
PrintPage ,Print Page printing page 2 part 1
PrintPage ,Current Margins are 0, 0, 461, 0
PrintPage ,Print Page printed rows 15 to 15
PrintPage ,Print Page printed columns 0,1,2,3,4,5
EmbeddedPrint,EmbeddedPrint process started
SetupPrint ,SetupPrint process started
SetupPrint ,Initial Printer Margins are 420, 0, 0, 0
SetupPrint ,PrintRange is AllPages
SetupPrintRange,Grid Printout Range is 6 columns
SetupPrintRange,Grid Printout Range is 5 rows
measureprintarea,PageSet 0 Information ----------------------------------------------
measureprintarea,Measured columns 0,1,2,3,4,5
measureprintarea,Original Column Widths: 60,32,32,32,32,32
measureprintarea,Overridden Column Widths: -1,-1,-1,-1,-1,-1
measureprintarea,Final Column Widths: 60,32,32,32,32,32
measureprintarea,pageset print width is 512, total column width to be printed is 220
|
|
|
|
|
It looks like what you are running into is the row counter is off for the second grid, and throwing an exception for the third grid. In the second grid you are printing 3 rows, but the print report is
AHSTech wrote: PrintPage ,Print Page printed rows 15 to 15
Are you re-using the same DGV object for each print? DGV was originally designed to not be reusable - each grid to be printed should have it's own DGV object. My guess is that it worked before just by the chance of which rows you were printing in your grids.
Steve G.
|
|
|
|
|
Thanks Steve, problem solved, head duly slapped.
Large Post-It with "RTFM" written on it now stuck to monitor
I'll rewrite my routine to use the new embedded print functionality in due course, but your uncanny awareness of my ineptitude will at least get me over the immediate problem quickly!
I really must stop working 12-hour days...
Cheers
Derek
|
|
|
|
|
Glad to be of help!
Steve G.
|
|
|
|
|
First of all, this class you have developed is AWESOME. I have been using it for years without a problem. Recently, one of the people that use our little tool was complaining about an error they get when trying to print on their new machine. The exception they are getting is as follows:
Message: Handle 0 is not valid.
Source: System.Drawing
StackTrace:
at System.Drawing.Printing.PrinterSettings.SetHdevmode(IntPtr hdevmode)
at System.Windows.Forms.PrintDialog.UpdatePrinterSettings(IntPtr hDevMode, IntPtr hDevNames, Int16 copies, Int32 flags, PrinterSettings settings, PageSettings pageSettings)
at System.Windows.Forms.PrintDialog.ShowPrintDialog(IntPtr hwndOwner, WndProc hookProcPtr, PRINTDLG data)
at System.Windows.Forms.PrintDialog.RunDialog(IntPtr hwndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog(IWin32Window owner)
at System.Windows.Forms.CommonDialog.ShowDialog()
at DGVPrinterHelper.DGVPrinter.DisplayPrintDialog()
at DGVPrinterHelper.DGVPrinter.PrintDataGridView(DataGridView dgv)
I have never had this as a problem on any clients previously. I believe all clients were using XP before. I think this new client is using Win8. Further testing has shown that this also happens on Win7. Is there a problem with different versions of the .NET framework on this? Is there something else I should be doing when setting up the DGVPrinterHelper? Here is how I am setting it up:
DGVPrinterHelper.DGVPrinter printer = new DGVPrinterHelper.DGVPrinter();
printer.Title = "Client List";
printer.SubTitle = " ";
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoClip;
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.Footer = "Printed on " + DateTime.Now.ToString("MM/dd/yyyy h:mm tt");
printer.FooterSpacing = 15;
printer.PrintDialogSettings.UseEXDialog = false;
printer.PrintDataGridView(this.dgvClients);
Thanks for your help in this!
Joe
|
|
|
|
|
Yes, there are differences between XP and Win 7/8. The first thing I would recommend trying (if you haven't already) is to use the most recent version of DGV Printer. The newer versions are specifically built for Win 7 and the later versions of .Net
Please don't hesitate to get back to me with more information if this does not fix your problem.
Steve G.
|
|
|
|
|
Hello Steve,
Thank you for the quick reply!! I have already tried the latest versions against the .NET Framework 4.0 (we were originally trying to avoid requiring all clients to upgrade to .NET 4.0, but from what I can gather it will not be an option to target both XP/7/8 with the same build). The latest versions give another problem (on my dev machine which is Win7 with .NET 4.5). When the new EX Print dialog pops up, another dialog comes with it stating:
"Before you can print, you need to select a printer. If you need to install a printer, either double-click the Add Printer icon or click the Find Printer... button located on the General tab of this dialog."
Click here for an image... http://tinypic.com/r/abjby9/5[^]
There are multiple printers in my list but whenever I select one the "Print" and "Apply" buttons are never un-greyed.
With further investigation, it appears that this message is because I don't have a "default" printer installed or setup -- however, I do. And in fact when I use the latest version against a test app that just has a simple DGV and the printing stuff, it works just fine.
If I add the following line of code, just prior to the pd.ShowDialog() in the DisplayPrintDialog() function:
IntPtr hDevmode = pd.PrinterSettings.GetHdevmode(pd.PrinterSettings.DefaultPageSettings);
I get an exception:
Message: No printers are installed.
Source: System.Drawing
StackTrace:
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal(String printer)
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal()
at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings pageSettings)
at DGVPrinterHelper.DGVPrinter.DisplayPrintDialog()
at DGVPrinterHelper.DGVPrinter.PrintDataGridView(DataGridView dgv)
at PROAssembly.GRFilter2.btnClientListPrint_Click(Object sender, EventArgs e)
MethodName: GetHdevmodeInternal
It seems that there is no default printer when I inspect some of the PrinterSettings. As I mentioned before, I definitely do have a default printer as this works with a little test app I wrote. Are there security concerns when using these printing classes? The application with the problem is fairly large (multi-assembly with dynamic loading of the dependent assemblies).
Thanks!
Joe
|
|
|
|
|
Are Terminal Server or networked printers involved anywhere in your setup? This http://support.microsoft.com/kb/831754[^]seems to relate to your problem. The other thing I'd look into is that you may have competing versions of printer drivers available for a networked printer.
Regarding the versions of .Net available, you are correct about not being able to target .Net 2/3/4 with a single build as the .NET interfaces have changed between versions.
Hope this helps,
Steve G.
|
|
|
|
|
Hello Steve,
No, this is not through Terminal Server. I am printing to a Networked Printer, but as I said, it works fine from a little test app. My suspicion is currently that for some reason the user context the module is running under, does not have the permissions to the printers. But, it should be running as me. From your knowledge, has any of the Printing security stuff changed in .NET4? That is all I can think of considering that it works in the little test app on all machines and does not work in the real app on any machines.
Thanks,
~Joe
|
|
|
|
|
Well - you've managed to shoot down my next suggestion quite nicely. I was going to suggest something to do with competing printer drivers between the local system and networked printer, but the working test program seems to push that idea out the door. Context security is also a possibility, but again, the test program works - I would assume that both the test and production programs would be running in your context?
The only other thing I can think of at the moment is that you've got a dll conflict somewhere (shades of 1999!). Are there any other printing functions in the production program?
Steve G.
|
|
|
|
|
Hah - good to know that I am offering good information in the first place . We do offer other printing through the program. It is done with a WebBrowser control...
WebBrowser.Document.ExecCommand("Print", true, null)
However, this code is never executed as part of the testing I am doing. It is in a totally separate part of the application (separate module).
As I mentioned before, the application is somewhat complex. It is modular, so that functionality can be added or removed without major new releases of the application. Essentially the flow of the program is as follows:
1. the basic .exe starts.
2. the exe looks at the other .dlls in the current running directory to see if they expose certain interfaces.
3. if they do, they are loaded to bring in that functionality to the application.
4. In one of the modules, there is the DGV that pulls information from a database. This is the information that should be printed.
I haven't built my test app to load a dll dynamically like we do in the real application. Although, I am thinking I might have to do that to verify that some sort of security thing is going on here. Do you have any other thoughts before I jump into all that work?
Thanks,
~Joe
BTW - you have been very responsive, I am EXTREMELY impressed with both the code and support!!!
|
|
|
|
|
Well, thanks for the compliments.
Unfortunately, I really can't think of any other possibilities at the moment; though I'd really be interested in what you find. Good luck with your extended testing!
Steve G.
|
|
|
|
|
Simple, powerful, and self-contained.
|
|
|
|
|
I love this, so straightforward. But is there a way to print preview without displaying the print dialog first? I think it might confuse users the way it is by default.
|
|
|
|
|
Typical programmer answer: "Yes, But ..."
You can skip the print preview dialog, the api call is PrintPreviewNoDisplay(datagridview). However, before you make this call you will need to provide the inputs that DGVPrinter gets from the preview dialog. That is, the PrinterSettings and PageSettings structures must be completed and attached to DGVPrinter.PrintDocument. See figure 5 in the section "Complex use of the DGVPrinter" for a rudimentary example.
Steve G.
|
|
|
|
|
|