|
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
|
|
|
|
|
I double checked the checkboxes column handling and it's working fine in my test program. Can you tell me more about your grid definition and how you're defining the checkbox column that's causing the problem?
Steve G.
|
|
|
|
|
Hi
This may be a dumb question as I'm a bit new to using Visual Studio 10 and c++/cli.
Can this be made to work with c++/cli?
I've tried your suggestions:
" ... place the DLL in your "Bin" directory and add a reference to the DGVPrinter.dll to your project's references ... "
using DGVPrinterHelper;
gives an error: " .. 'DGVPrinterHelper' : symbol cannot be used in a using-declaration"
|
|
|
|
|
Ok, found my mistake:
using namespace DGVPrinterHelper;
did the trick BUT [ there is always one of those ]
PrintDialog printDialog = gcnew PrintDialog();
produces: 'System::Windows::Forms::PrintDialog' : class does not have a copy-constructor
Now I'm really stuck.
Any help much appreciated.
Thanks
|
|
|
|
|
I'm glad you found your way past the first error. I'm kind of confused about this one, though. Am I correct in assuming that this is in your code and you're attempting to use the DGVPrinter? My C++ is kinda (ok, VERY) rusty, but don't you need a pointer or handle type for return from a new operation?
Steve G.
|
|
|
|
|
Hi
Got it working with a few parameter settings generating errors so I've commented out the lines in the example shown below. If someone can help sort the issues then that would be great.
DGVPrinter printer ;
printer.Title = "DataGridView Report";
printer.SubTitle = "An Easy to Use DataGridView Printing Object";
//printer.SubTitleFormatFlags = StringFormatFlags.LineLimit || StringFormatFlags.NoClip;
printer.PageNumbers = true;
printer.PageNumberInHeader = false;
//printer.ColumnWidth = DGVPrinter::ColumnWidthSetting->Proportional;
//printer.HeaderCellAlignment = StringAlignment.Near;
printer.Footer = "Your Company Name Here";
printer.FooterSpacing = 15;
printer.PrintDataGridView(name_of_dataviewgrid);
Output looks sweet. Just need to test on a datagridview with more than one page of entries.
|
|
|
|
|
Interesting to me that three of those four lines (and the fourth may also) use enum values. I'd take differing enum handling between C# and C++ as a place to start looking to solve your compile problems.
Steve G.
|
|
|
|
|
Simple, full of features and works great! Thanks for contributing!
|
|
|
|
|
works fine. Thanks, what about strike out fonts ?
|
|
|
|
|
Strikeout fonts houldn't be a problem Just set the font the same way you would normally.
Steve G.
|
|
|
|
|