|
Methods to do this start on pg. 10 of the documentation. And, you just made me realize that I neglected to number the pages in the documentation. Heh - one more item for the next revision.
Steve G.
|
|
|
|
|
Welll, it wasn't exactly obvious that that was documentation. I was expecting something different and didn't exactly know that I had to do it as follows:
Printer.TitleFont = New Font("Tacoma", 14, FontStyle.Regular)
Maybe a snippet of code for each property would be illustrative (for us folks that are still trying to get our arms around this beast (VB.Net)). However, I am impressed that there is even 'documentation'.
But indeed it does work. Tks, OH
|
|
|
|
|
Dear author,
is it possible somehow to add a row number for each row to the printed page? I know, that i can add a column with this information, but i think, that more people would appretiate, if this functionallity would be built-in.
Example
I have grid with this data
Jane Doe
Joe Doe
I would like to have on the printed page
1 Jane Doe
2 Joe Doe
If it is possible to do it know somehow, please let me know. Thank you and great job!
|
|
|
|
|
Had to think about this one for a while. At this point, I don't see this as a feature that fits within what DGVPrinter is trying to do. That said, this is a very creative and interesting suggestion - it really made me think!
Thanks for the suggestion -
Steve G.
|
|
|
|
|
I believe it's "Proportional" not "Porportional".
Otherwise, your code was really easy to just plug-in and go.
Ryan C. Price
|
|
|
|
|
Hmm... learn something new every day.
Thanks!
Steve G.
|
|
|
|
|
Hi
I'm using your lovely dll in a project I'm working on to print a datagridview using the simply version. My c++/cli coding uses:
DGVPrinter printer;
printer.Title = "A Title";
printer.PorportionalColumns = true;
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.Footer = "footer";
printer.FooterSpacing = 15;
printer.PrintDataGridView(dgvsheet);
and it works fine EXCEPT that I need the rows to be at a greater height. I was hoping the line I needed went:
printer.RowHeight =
but I've absolutely no idea what would come next.
Can I do this and, if so, how?
Brian
|
|
|
|
|
The easiest and simplest way to do this is to alter the row heights in your grid, and then tell the printer object to use the "CellHeights" setting. In C# this would be:
printer.RowHeight = DGVPrinter.RowHeightSetting.CellHeight;
If you find that the data in the cell just isn't "fitting" then use "DataHeight" instead of "CellHeight".
What I'm not sure of is how you would gain access the enum "RowHeightSetting" in c++. I mention this as someone mentioned having issues with the enums in C++ in a recent post.
The issue with just setting the row heights is that DGVPrinter does a lot of calculation to determine the row heights (given that you can change fonts, etc.) to try to ensure that the data in the cells will show in the printout, and to know when to insert page breaks.
Hope this helps,
Steve G.
|
|
|
|
|
Thanks for that feedback.
I don't suppose you remember who/when enum was mentioned do you? I ask as a search didn't find anything.
nz556
|
|
|
|
|
Hi again Steve,
Another minor problem - updated to your latest version and my code line of:
printer.PrintSettings.DefaultPageSettings.Landscape = true;
isn't working anymore. Has this been changed?
Joe
|
|
|
|
|
"Nothing has changed" - however, this is the second recent report of something fishy with landscape printing. I'm going to take a look into this and see if I can find anything. Can you send some more details on what you're doing to help me track this down?
Thanks,
Steve G.
|
|
|
|
|
Thanks Steve,
I am pressing a toolstrip button to process the following event (listed in full below):
private void printToolStripButton_Click(object sender, EventArgs e)
{
DGVPrinter printer = new DGVPrinter();
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit |
StringFormatFlags.NoClip;
printer.ColumnStyles[rentalPrintGridView.Columns[0].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[0].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[0].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnStyles[rentalPrintGridView.Columns[0].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[0].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[0].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[0].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[0].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[1].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[1].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[1].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnStyles[rentalPrintGridView.Columns[1].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[1].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[1].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[1].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[1].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[2].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[2].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[2].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[2].Name, 55);
printer.ColumnStyles[rentalPrintGridView.Columns[2].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[2].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[2].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[2].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[2].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[3].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[3].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[3].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[3].Name, 25);
printer.ColumnStyles[rentalPrintGridView.Columns[3].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[3].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[3].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[3].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[3].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[4].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[4].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[4].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[4].Name, 30);
printer.ColumnStyles[rentalPrintGridView.Columns[4].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[4].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[4].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[4].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[4].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[5].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[5].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[5].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[5].Name, 75);
printer.ColumnStyles[rentalPrintGridView.Columns[5].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[5].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[5].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[5].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[5].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[6].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[6].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[6].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[6].Name, 50);
printer.ColumnStyles[rentalPrintGridView.Columns[6].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[6].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[6].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[6].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[6].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[7].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[7].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[7].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[7].Name, 50);
printer.ColumnStyles[rentalPrintGridView.Columns[7].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[7].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[7].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[7].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[7].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[8].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[8].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[8].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[8].Name, 25);
printer.ColumnStyles[rentalPrintGridView.Columns[8].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[8].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[8].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[8].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[8].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[9].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[9].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[9].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[9].Name, 50);
printer.ColumnStyles[rentalPrintGridView.Columns[9].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[9].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[9].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[9].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[9].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[10].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[10].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[10].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[10].Name, 125);
printer.ColumnStyles[rentalPrintGridView.Columns[10].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[10].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[10].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[10].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[10].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[11].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[11].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[11].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[11].Name, 50);
printer.ColumnStyles[rentalPrintGridView.Columns[11].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[11].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[11].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[11].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[11].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[12].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[12].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[12].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[12].Name, 50);
printer.ColumnStyles[rentalPrintGridView.Columns[12].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[12].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[12].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[12].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[12].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[13].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[13].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[13].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[13].Name, 50);
printer.ColumnStyles[rentalPrintGridView.Columns[13].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[13].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[13].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[13].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[13].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[14].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[14].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[14].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[14].Name, 40);
printer.ColumnStyles[rentalPrintGridView.Columns[14].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[14].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[14].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[14].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[14].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[15].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[15].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[15].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[15].Name, 75);
printer.ColumnStyles[rentalPrintGridView.Columns[15].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[15].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[15].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[15].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[15].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[16].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[16].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[16].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[16].Name, 125);
printer.ColumnStyles[rentalPrintGridView.Columns[16].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[16].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[16].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[16].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[16].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnStyles[rentalPrintGridView.Columns[17].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnStyles[rentalPrintGridView.Columns[17].Name].Font = new Font("Arial", (float)5.5);
printer.ColumnStyles[rentalPrintGridView.Columns[17].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnWidths.Add(rentalPrintGridView.Columns[17].Name, 125);
printer.ColumnStyles[rentalPrintGridView.Columns[17].Name].WrapMode = DataGridViewTriState.True;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[17].Name] = rentalPrintGridView.DefaultCellStyle.Clone();
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[17].Name].Font = new Font("Arial", (float)5.5, FontStyle.Bold);
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[17].Name].Alignment = DataGridViewContentAlignment.MiddleCenter;
printer.ColumnHeaderStyles[rentalPrintGridView.Columns[17].Name].WrapMode = DataGridViewTriState.True;
string EffDateStart = Convert.ToString(startDateToolStripTextBox.Text);
string EffDateFinish = Convert.ToString(endDateToolStripTextBox.Text);
string Code1 = Convert.ToString(code1ToolStripTextBox.Text);
string Code2 = Convert.ToString(code2ToolStripTextBox.Text);
string Code3 = Convert.ToString(code3ToolStripTextBox.Text);
string Street1 = Convert.ToString(street1ToolStripTextBox.Text);
string Suburb1 = Convert.ToString(suburb1ToolStripTextBox.Text);
string Suburb2 = Convert.ToString(suburb2ToolStripTextBox.Text);
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.Title = "S&P Rental Database";
printer.SubTitle = "Effective Date: " + EffDateStart + " - " + EffDateFinish + ", Code: " + Code1 + " " + Code2 + " " + Code3 + ", Street: " + Street1 + ", Suburb: " + Suburb1 + " " + Suburb2;
printer.Footer = "Saunders & Pitt";
printer.FooterSpacing = 15;
printer.PrintSettings.DefaultPageSettings.Landscape = true;
printer.PrintDataGridView(rentalPrintGridView);
}
That is using the older version of DGVPrinter and it works as it should. When I change it to the most recent version, everything works except default page layout is portrait. I have made no other changes except updating class file.
Joe
|
|
|
|
|
Also,
Sorry if my code is long winded and not as you intended it to be written!
|
|
|
|
|
Try
printer.PageSettings.Landscape = true;
This is what I have in my test suite. In my experience, much of the "DefaultPageSettings" gets ignored by Windows. Which is odd because you'd think that Windows printing exposing a "DefaultPageSettings" would actually let you set the default page settings. :-P
Steve G.
|
|
|
|
|
Hey,
Has been a while but I'm back to using this great bit of code!
However, I am finding that when I press the print button (a toolstrip button), the print dialogue is not active. I have to click once to make it active, and then it will work (in other words I have to click print twice in order to print).
Any idea what might be causing this?
Joe
|
|
|
|
|
Not really related to DGVPrinter, but this sounds like a focus issue - first click puts the focus into your application, second click is actually picked up and the event sent to the button handler.
Steve G.
|
|
|
|
|
Thanks Steve,
Sorry to bother you with the problem but this is the code that happens when the toolstrip button is clicked:
private void printToolStripButton_Click(object sender, EventArgs e)
{
DGVPrinter printer = new DGVPrinter();
printer.SubTitleFormatFlags = StringFormatFlags.LineLimit |
StringFormatFlags.NoClip;
string EffDateStart = Convert.ToString(startDateToolStripTextBox.Text);
string EffDateFinish = Convert.ToString(endDateToolStripTextBox.Text);
string Code1 = Convert.ToString(code1ToolStripTextBox.Text);
string Code2 = Convert.ToString(code2ToolStripTextBox.Text);
string Code3 = Convert.ToString(code3ToolStripTextBox.Text);
string Street1 = Convert.ToString(street1ToolStripTextBox.Text);
string Suburb1 = Convert.ToString(suburb1ToolStripTextBox.Text);
string Suburb2 = Convert.ToString(suburb2ToolStripTextBox.Text);
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Near;
printer.Title = "S&P Rental Database";
printer.SubTitle = "Effective Date: " + EffDateStart + " - " + EffDateFinish + ", Code: " + Code1 + " " + Code2 + " " + Code3 + ", Street: " + Street1 + ", Suburb: " + Suburb1 + " " + Suburb2;
printer.Footer = "Saunders & Pitt";
printer.FooterSpacing = 15;
printer.PrintSettings.DefaultPageSettings.Landscape = true;
printer.PrintDataGridView(rentalPrintGridView);
}
There is a heap of settings for each column in there as well which I have omitted. Does anything jump out at you which is incorrect and causing the loss of focus? Or is there a simple focus command I need to put in?
Cheers,
Joe
|
|
|
|
|
Since you're having to click once to (it appears) set the focus, this is a more of an external issue, unrelated to your button handler. Do you know what might be grabbing the focus away from your main app?
Steve G.
|
|
|
|
|
Actually, I've noticed the same problem. I created a new test project to reproduce it simply.
One form, containing:
One grid with three text columns,
Toolstrip with one 'Print List' button.
It demonstrates the behaviour, so I don't think it is an external problem.
I've moved the designer code so that it is one file, with the button handler right at the top:
using System;
using System.Windows.Forms;
namespace DgvPrintTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
DGVPrinterHelper.DGVPrinter dp = new DGVPrinterHelper.DGVPrinter();
dp.PrintPreviewDataGridView(this.dataGridView1);
}
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripButton1 = new System.Windows.Forms.ToolStripButton();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.SuspendLayout();
this.toolStrip1.Font = new System.Drawing.Font("Segoe UI", 9.75F);
this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripButton1});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(552, 25);
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
this.toolStripButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
this.toolStripButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButton1.Image")));
this.toolStripButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
this.toolStripButton1.Name = "toolStripButton1";
this.toolStripButton1.Size = new System.Drawing.Size(61, 22);
this.toolStripButton1.Text = "Print List";
this.toolStripButton1.Click += new System.EventHandler(this.toolStripButton1_Click);
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.Column1,
this.Column2,
this.Column3});
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGridView1.Location = new System.Drawing.Point(0, 25);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(552, 325);
this.dataGridView1.TabIndex = 1;
this.Column1.HeaderText = "Column1";
this.Column1.Name = "Column1";
this.Column2.HeaderText = "Column2";
this.Column2.Name = "Column2";
this.Column3.HeaderText = "Column3";
this.Column3.Name = "Column3";
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(552, 350);
this.Controls.Add(this.dataGridView1);
this.Controls.Add(this.toolStrip1);
this.Name = "Form1";
this.Text = "Form1";
this.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private ToolStrip toolStrip1;
private ToolStripButton toolStripButton1;
private DataGridView dataGridView1;
private DataGridViewTextBoxColumn Column1;
private DataGridViewTextBoxColumn Column2;
private DataGridViewTextBoxColumn Column3;
}
}
Ryan C. Price
|
|
|
|
|
This works to have focus...
Comment out pd.UseEXDialog = printDialogSettings.UseEXDialog;
in DisplayPrintDialog()
Great solution btw!
|
|
|
|
|
Your Printer is very nice, but I have one question: How can I make it that the printer prints in landscape?
mfg KapuzenSohn
|
|
|
|
|
Change the printer settings to landscape mode before printing the grid with DGVPrinter.
|
|
|
|
|
Use
print.PageSettings.Landscape = true; in your code to force landscape mode.
Steve G.
|
|
|
|
|
I am trying to print 3 separate dgvs. When there is no checkbox column this code is beautiful. If there is a checkbox column then it prints headers and footers, but no data.
|
|
|
|
|
Hmm... Can you tell me a bit more about what you're trying to do and how your grids are defined?
Thanks,
Steve G
|
|
|
|
|