Hi Guys,
I am trying to take print of my datagrid, it asks me to print it and it does. but when i see the file the file is empty.there is no data and the file is empty. File is xps. i tried code from microsoft site and from other site as well. but problem is same.
Microsoft Link
and other code.
Its getting on my nerves
I am trying to take print of my datagrid, it asks me to print it and it does. but when i see the file the file is empty.there is no data and the file is empty. File is xps. i tried code from microsoft site and from other site as well. but problem is same.
Microsoft Link
and other code.
DataGridViewPrinter MyDataGridViewPrinter;
private bool SetupThePrinting()
{
PrintDialog MyPrintDialog = new PrintDialog();
MyPrintDialog.AllowCurrentPage = false;
MyPrintDialog.AllowPrintToFile = false;
MyPrintDialog.AllowSelection = false;
MyPrintDialog.AllowSomePages = false;
MyPrintDialog.PrintToFile = false;
MyPrintDialog.ShowHelp = false;
MyPrintDialog.ShowNetwork = false;
if (MyPrintDialog.ShowDialog() != DialogResult.OK)
return false;
MyPrintdocument.DocumentName = "Customers Report";
MyPrintdocument.PrinterSettings =
MyPrintDialog.PrinterSettings;
MyPrintdocument.DefaultPageSettings =
MyPrintDialog.PrinterSettings.DefaultPageSettings;
MyPrintdocument.DefaultPageSettings.Margins =
new Margins(40, 40, 40, 40);
if (MessageBox.Show("Do you want the report to be centered on the page",
"InvoiceManager - Center on Page", MessageBoxButtons.YesNo,
MessageBoxIcon.Question) == DialogResult.Yes)
MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView,
MyPrintDocument, true, true, "Customers", new Font("Tahoma", 18,
FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);
else
MyDataGridViewPrinter = new DataGridViewPrinter(MyDataGridView,
MyPrintDocument, false, true, "Customers", new Font("Tahoma", 18,
FontStyle.Bold, GraphicsUnit.Point), Color.Black, true);
return true;
}
private void printToolStripButton_Click(object sender, EventArgs e)
{
if (SetupThePrinting())
MyPrintdocument.Print();
}
private void MyPrintDocument_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
bool more = MyDataGridViewPrinter.DrawDataGridView(e.Graphics);
if (more == true)
e.HasMorePages = true;
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (SetupThePrinting())
{
PrintPreviewDialog MyPrintPreviewDialog = new PrintPreviewDialog();
MyPrintPreviewDialog.Document = MyPrintDocument;
MyPrintPreviewDialog.ShowDialog();
}
}
Its getting on my nerves