Printing DataGridView
Post your questions regarding programming in C# in here.
7 posts
Page 1 of 1
Hello!
I would like to print the information which is in DataGridView in C#. Is it possible? How can i do that?
I would like to print the information which is in DataGridView in C#. Is it possible? How can i do that?
yes its possible :lol:
but can't help you with c# :(
i know only in vb :lol:
but can't help you with c# :(
i know only in vb :lol:
visit us on:
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
Here is a simple way to print the data as text:
Code: Select all
private void btnPrint_Click(object sender, EventArgs e)
{
PrintDialog dialog = new PrintDialog();
DialogResult dr = dialog.ShowDialog();
if (dr == DialogResult.OK)
{
PrintDocument document = new PrintDocument();
document.PrinterSettings = dialog.PrinterSettings;
document.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(Document_PrintPage);
document.Print();
}
}
void Document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int y = 0;
for (int row = 0; row < dataGridView1.Rows.Count; row++)
{
int x = 0;
for (int col = 0; col < dataGridView1.Columns.Count; col++)
{
if (dataGridView1.Rows[row].Cells[col].Value != null)
{
string value = dataGridView1.Rows[row].Cells[col].Value.ToString();
e.Graphics.DrawString(value, dataGridView1.Font, Brushes.Black, new PointF(x, y));
}
x += 30;
}
y += 15;
}
}
the code is whowing an error here:
printDocument1 document = new PrintDocument1();
is there any thing to do before inserting the code?
I put PrintDialog and PrintDocument
but is showing error
printDocument1 document = new PrintDocument1();
is there any thing to do before inserting the code?
I put PrintDialog and PrintDocument
but is showing error
There is no place it shows PrintDocument1, it is supposed to be PrintDocument
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
I put PrintDialog and PrintDocumentIf you haven't already, you will need to add this reference:
but is showing error
Code: Select all
using System.Drawing.Printing;
7 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023